[CMake] weird linking breaks debugging?

Victor Mataré matare at fh-aachen.de
Tue Jun 26 19:58:32 EDT 2018


Hi all,

On Linux, if I'm creating a lib and an executable:

add_library(something SHARED ${LIB_SRC})
add_executable(some-exec ${EXEC_SRC})
target_link_libraries(some-exec something)

Then the linker always links against libsomething.so instead of -lsomething.
For some reason this causes the shared object to be compiled into the the binary:

$ ldd some-exec 
        linux-vdso.so.1 (0x00007ffd1292b000)
        libsomething.so (0x00007fd9b346e000)
[...]

It's nice I can run the binary without setting LD_LIBRARY_PATH, but the debugger doesn't like it. When debugging some-exec, I can't autocomplete any symbols from the lib, and I can't set breakpoints there. If gdb somehow stops within a frame in libsomething, the symbols become available and I can debug normally.

In qt-creator it's even worse, there my breakpoints end up in all the wrong places and I can't get the program to stop inside the libsomething in a controlled manner.

So how do I tell cmake not to produce one huge mess of a binary? I've tried setting NO_SONAME to 1, but that doesn't change anything. Also, why doesn't cmake just use DT_RUNPATH=$ORIGIN?

Thanks, Victor




More information about the CMake mailing list