Native CMake library not being linked
Posted: Wed Oct 11, 2023 12:03 pm
I have a native [.cpp] CMake library, which is already successfully built and used under native CMake for Linux and Windows in the usual way (i.e. add_library(), target_include_directories() and then a call to target_link_libraries() following add_executable()) which I would like to use within the ESP-IDF world.
From the instructions here:
https://docs.espressif.com/projects/esp ... components
...I believe that, provided that the library (named geodesic) is created with:
...[which it is] then it should be linked with my application if I include geodesic in my list of required components, so:
I can see that ESP-IDF is compiling all of the files that comprise geodesic and that a library of name libgeodesic.a is being created. If I print COMPONENT_REQUIRES from within CMakeLists.txt, geodesic is definitely in the list:
However, linking the final target fails because the functions that my application calls which are inside the geodesic library aren't present, e.g.:
What might I be doing wrong?
I've tried making the target_include_directories() of type PUBLIC, in case that is upsetting C++ somehow (all of the other files built into the application are only .c code), but that doesn't help. I don't believe there is anything wrong with the code or header files themselves since, with exactly the same code and CMake files, GCC under Linux and MSVC under Windows build (and run) to completion.
I've also tried adding a plain-old .c file to the geodesic library and calling a function in that from my main code: that function also seems to be unavailable, so this is not just a C++ thing, the entire libgeodesic.a is not being given to the link stage for some reason.
From the instructions here:
https://docs.espressif.com/projects/esp ... components
...I believe that, provided that the library (named geodesic) is created with:
Code: Select all
add_library(geodesic STATIC ${GEODESIC_SRC})
target_include_directories(geodesic PRIVATE ${GEODESIC_INC})
Code: Select all
COMPONENT_REQUIRES(... geodesic)
Code: Select all
COMPONENT_REQUIRES is driver;esp_timer;mbedtls;esp_system;geodesic
Code: Select all
[653/658] Linking CXX executable final.elf
FAILED: final.elf
cmd.exe /C "cd . && C:\Users\rmea\.ubxlibpkg\esp_idf_tools-v5.0.3\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\final.elf.rsp -o final.elf && cd ."
c:/users/rmea/.ubxlibpkg/esp_idf_tools-v5.0.3/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/final/libmain.a(geodesic_user.cpp.obj):(.literal.uGnssFenceWgs84GeodDirect+0x0): undefined reference to `GeographicLib::Geodesic::WGS84()'
c:/users/rmea/.ubxlibpkg/esp_idf_tools-v5.0.3/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/final/libmain.a(geodesic_user.cpp.obj):(.literal.uGnssFenceWgs84GeodDirect+0x4): undefined reference to `GeographicLib::Geodesic::GenDirect(double, double, double, bool, double, unsigned int, double&, double&, double&, double&, double&, double&, double&, double&) const'
...
I've tried making the target_include_directories() of type PUBLIC, in case that is upsetting C++ somehow (all of the other files built into the application are only .c code), but that doesn't help. I don't believe there is anything wrong with the code or header files themselves since, with exactly the same code and CMake files, GCC under Linux and MSVC under Windows build (and run) to completion.
I've also tried adding a plain-old .c file to the geodesic library and calling a function in that from my main code: that function also seems to be unavailable, so this is not just a C++ thing, the entire libgeodesic.a is not being given to the link stage for some reason.