cmake prepending part of the build directory into the library path

Viewed 20

I've got a cmake file that builds a shared library, a binary, and then links them. This seems to work fine, until I go to run it on the target machine. I was expecting that just the library's name would be defined, and the loader would search for the library along the LD_LIBRARY_PATH, however what I see when I run it is different:

/bin/my_prog: error while loading shared libraries: builds/debug/lib/my_lib.so.2: cannot open shared object file: No such file or directory

src/my_lib/builds/debug/lib is where the library is stored during the build process (created with externalproject_add), but I don't see why it's seemingly picked a random subset of this directory to use as part of the search path.

I've tried playing with the rpath:

set( CMAKE_SKIP_BUILD_RPATH true )

to no avail.

I'm a bit at a loss as to what to try next, as the loader/linker are not my strong suit. What's causing cmake to do this?

Edit:

The cross compile is simply created by using a different toolchain:

toolchain=x86_64-silvermont-linux-gnu

The relevant part of the cmake file:

add_library(dx1 SHARED
    src/lib/phy.c
    )

ExternalProject_Add(my_lib
    BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/my_lib/sdk 
    CONFIGURE_COMMAND "" 
    BUILD_COMMAND "make"
    INSTALL_COMMAND ""
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/my_lib/sdk
    LOG_BUILD 1 
    LOG_OUTPUT_ON_FAILURE 1
    BUILD_ALWAYS)

find_library(MY_LIB
    NAMES my_lib.so.2
    PATHS ${CMAKE_CURRENT_SOURCE_DIR}/my_lib/builds/debug/lib
    #PATH_SUFFIXES lib
    NO_CMAKE_FIND_ROOT_PATH
    NO_CMAKE_PATH
    NO_CMAKE_SYSTEM_PATH)

target_link_libraries(dx1 ${MY_LIB} rt)

add_executable(unittest_main src/test/main.c)
target_link_libraries(unittest_main dx1)

Also important to note that the rt library seems to link just fine:

/ # ldd /bin/unittest_main
    linux-vdso.so.1 (0x00007ffee53ed000)
    libdx1.so => /usr/lib64/libdx1.so (0x00007f756ebe1000)
    builds/debug/lib/my_lib.so.2 => not found
    librt.so.1 => /lib64/librt.so.1 (0x00007f756ebd7000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f756ea1b000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f756e9fa000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f756ebe8000)

This appears to be a specific issue with the library built with externalproject_add

0 Answers
Related