0

I'm getting this error while cross-compiliing mosquitto library.

Linking C executable mosquitto
/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: CMakeFiles/mosquitto.dir/security.c.obj: undefined reference to symbol 'dlopen@@GLIBC_2.4'
/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /lib/arm-linux-gnueabihf/libdl.so.2: error adding symbols: DSO missing from command line

I'm quite new with CMake and I don't know how to specify to use this library. I've tried with options, but have no luck.

add_link_options(-ldl)
add_link_options(-dl)

And this is my arm toolchain

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(COMPILER_PREFIX arm-linux-gnueabihf-)

set(CMAKE_C_COMPILER    ${COMPILER_PREFIX}gcc)
set(CMAKE_CXX_COMPILER  ${COMPILER_PREFIX}g++)
set(CMAKE_AR            ${COMPILER_PREFIX}ar)
set(CMAKE_RANLIB        ${COMPILER_PREFIX}ranlib)

set(CMAKE_ASM_COMPILER  ${COMPILER_PREFIX}gcc)
set(CMAKE_OBJCOPY       ${COMPILER_PREFIX}objcopy)
set(CMAKE_OBJDUMP       ${COMPILER_PREFIX}objdump)
set(CMAKE_SIZE          ${COMPILER_PREFIX}size)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Please, can someone help?

ck0ba
  • 1
  • 1
  • Does this answer your question? [Need to link cmake project to dl library](https://stackoverflow.com/questions/33678965/need-to-link-cmake-project-to-dl-library) – Kevin Apr 30 '20 at 23:34
  • or this? https://stackoverflow.com/q/20131138/3987854 – Kevin Apr 30 '20 at 23:35
  • Unfortunately no. I'm using mosquitto library through add_subdirectory and I cannot control how mosquitto is linked. Here, the problem is while linking mosquitto lib, not while linking mosquitto with my app. Thanks for answer. – ck0ba Apr 30 '20 at 23:46
  • Now I changed CMakeLists.txt of mosquitto lib, I just added dl in target_link_libraries and it works, but I am not allowed to do that – ck0ba Apr 30 '20 at 23:56
  • "... I am not allowed to do that" - So, your **real question** is why mosquitto project isn't built, am I right? Have you tried to build mosquitto project **standalone** (not via `add_subdirectory`) and **natively** (not cross-compile)? Have you faced the same errors? If no, than something could be wrong either with a way you include mosquitto project into your one, or with your toolchain. Since you don't show neither of these code, we could only guess. – Tsyvarev May 01 '20 at 00:32
  • Yes, when I build it natively everything is ok. I checked linker search paths and that's ok also. It covers all necessary dirs(native and cross-compile - arm-linux-gnueabihf), and those libs are on the right place. I included mosquitto just with add_subdirectory and the linked it with my app. And you can see now how my toolchain looks. – ck0ba May 01 '20 at 09:43

0 Answers0