Unrecognized library in native environment

Hi there

I’m trying to compile both native and esp32 environments using a shared library, however, it compiles and executed fine at esp32, but sereral errors arised on native environment.

First, it doesn’t recognize the added library lib_deps config.
Solved by overriding this issue by adding -I<path-to-lib-src> inside build_flags, but a linking error regarding the library API is arised undefined reference to ....

platformio.ini:

[platformio]
default_envs = 
	esp32doit

[common]
lib_deps = 
	https://github.com/HamzaHajeir/pmbtools.git
build_flags = 

lib_ldf_mode = deep+
[embedded]
lib_deps = 
	${common.lib_deps}
build_flags = 
	-std=gnu++2a
	-DEMBEDDED_PLATFORM=1
	${common.build_flags}

lib_ldf_mode = ${common.lib_ldf_mode}
build_unflags = 
	-std=gnu++11
monitor_speed = 115200
upload_speed = 921600

[esp32]
lib_deps = 
	${embedded.lib_deps}
build_flags = 
	-DESP32=1
	-DARDUINO_ARCH_ESP32=1
	-DBOARD_HAS_PSRAM
	${embedded.build_flags}
build_unflags = 
	${embedded.build_unflags}
lib_ldf_mode = ${embedded.lib_ldf_mode}

[env:esp32doit]
platform = espressif32@^5.2.0
board = esp32doit-devkit-v1
framework = arduino
lib_deps = 
	${esp32.lib_deps}
lib_ldf_mode = ${esp32.lib_ldf_mode}

build_flags = 
	${esp32.build_flags}
build_unflags = 
	${esp32.build_unflags}

[env:native]
platform = native
lib_deps = 
	${common.lib_deps}
lib_ldf_mode = ${common.lib_ldf_mode}

build_flags = 
	${common.build_flags}
    -I .pio/libdeps/native/pmbtools/src
	-std=c++20
	-O2
build_unflags = 
	-std=c++11

main.cpp:

#include "pmbtools.h"

void call()
{
  auto rv = join({"Hello", " ", "world"});
}
#ifdef EMBEDDED_PLATFORM
#include <Arduino.h>

void setup()
{
  // put your setup code here, to run once:
  call();
}

void loop()
{
  // put your main code here, to run repeatedly:
}
#else

int main()
{
  call();
}
#endif

The complete environment is uploaded to GitHub.

Any idea/solution?

Adding an unrecognized library with -I flag is 99.999% of the time the wrong way. The includes will be visible but the .cpp/.c files will not be compiled and you get exactly “undefined reference to <symbol>” errors.

If you have added the pmbtools to the lib_deps, are referencing the library directly in an #include statement in your source files but it still won’t show up, it may be because the library dependency finder find the library to be incompatible due to framework or platform restrictions declared in the library.json or library.properties. Set

lib_compat_mode = off

(docs) in the native environment to test that.

1 Like

Thank you @maxgerhardt, it was really the lib_compat_mode issue.

I think if a library only has a library.properties as its manifest file, which is an Arduino-only format, PlatformIO will declare the library to compatible with only framework = arduino and the architectures declared in the file, and so the native environment which does not have framework = arduino (and how should it) is deemed incompatible. Thus the lib compat check must be turned off here.

1 Like

I see your point, thanks @maxgerhardt for the explanation!