ck0ba
ck0ba

Reputation: 1

How to specify gcc to use "libdl.so.2" library for linking using CMake?

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?

Upvotes: 0

Views: 1019

Answers (0)

Related Questions