Native CMake library not being linked

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Native CMake library not being linked

Postby RobMeades » 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:

Code: Select all

add_library(geodesic STATIC ${GEODESIC_SRC})
target_include_directories(geodesic PRIVATE ${GEODESIC_INC})
...[which it is] then it should be linked with my application if I include geodesic in my list of required components, so:

Code: Select all

COMPONENT_REQUIRES(... geodesic)
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:

Code: Select all

COMPONENT_REQUIRES is driver;esp_timer;mbedtls;esp_system;geodesic
However, linking the final target fails because the functions that my application calls which are inside the geodesic library aren't present, e.g.:

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'
...
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.
Last edited by RobMeades on Wed Oct 11, 2023 2:56 pm, edited 1 time in total.

bidrohini
Posts: 202
Joined: Thu Oct 27, 2022 12:55 pm

Re: Native CMake library not being linked

Postby bidrohini » Wed Oct 11, 2023 2:23 pm

The same error message has been discussed here. You can take a look for clues.
https://esp32.com/viewtopic.php?t=33058

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: Native CMake library not being linked

Postby RobMeades » Wed Oct 11, 2023 2:43 pm

Hi, and thanks for that. Checking, in that case it was something to do with "how many HID devices should show up", a setting in menuconfig, which unfortunately doesn't apply in my case; my code is pure C/C++, no HW involved.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 351 guests