Library in lib/ directory gets built but not linked against

Hi,

I’ve added a custom library to the lib/ directory in my platformio project. The structure looks like this:

|--lib/
|  |--lua/
|  |  |--src/
|  |  |  |- ...
|
|--src/
|  |- main.cpp

In the main.cpp I’m using a method from the library:

#include <lauxlib.h>
...
void setup() {
   auto* luaState = luaL_newstate();
}

I’ve also added the library as a dependency in the platform.ini:

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
lib_deps =  lua

Also I find out that the library gets built to a liblua.a in .pio/build/nodemcu-32s/lib02a/liblua.a. With readelf I also made sure that the symbol is in the library:

>>> readelf -s liblua.a  | grep newstate
394: 00000000    43 FUNC    GLOBAL DEFAULT  282 luaL_newstate

However when I’m trying to build my project at the linking stage I’ll get an undefined reference to `luaL_newstate()’ in my main.cpp.o. I did an verbose build and saw that no lua library was passed to the linker in the build command. Can anyone help me and show me what I’m doing wrong? Thanks in advance

After searching a litte be more i finally found this thread: Private lib: undefined reference - Libraries - PlatformIO Community. The solution is to put the #include inside extern “C”:

extern "C" {
#include <lauxlib.h>
}