[CMake] cmake 2.8.12 - How to prevent target executable having dependency to prefixed path of target shared libraries

Couch, Kelly J kelly.j.couch at intel.com
Tue Nov 21 19:42:26 EST 2017


I am using cmake to build a binary with multiple shared libraries (some built and some on the system). I want the resulting executable to have dependencies on the required shared libraries (WITHOUT prefixed path to the library).

Specific build environment:
OpenSuse 11.3
cmake 2.8.12 and 
gcc: i686-linux5.0-gcc (GCC) 4.6.3
g++: g++ (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]

When specifying target_link_libraries(tgtA libA), the result is a tgtA with library linked using a relative path to the libA. For example, when using 'ldd tgtA', result is something like:

...
                libpthread.so.0 => /lib/libpthread.so.0 (0xf6290000)
                /lib/ld-linux.so.2 (0xf7758000)
                librt.so.1 => /lib/librt.so.1 (0xf6286000)
--->        directoryA/directoryB/libA.so => not found

Additional details:
1. The same cmake files work as expected on other linux distributions. It is only the specified config above that I encounter this issue.
2. I've various combinations of setting/NOT-setting all of these, trying to overcome this issue: CMAKE_BINARY_DIR, CMAKE_ARCHIVE_OUTPUT_DIRECTORY, CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_LIBRARY_OUTPUT_DIRECTORY, CMAKE_SKIP_RPATH, CMAKE_SKIP_INSTALL_RPATH
3. The behavior of prefixed library occurs on libraries that are built targets and library found using find_library
4. when I examine resulting link.txt file, the link command line includes the path to the shared library (so). Why doesn't cmake use -L to express the path to look and then only pass the library name as -l? Looks like "g++ <options> -o tgtA /directoryA/directoryB/libA.so"

I have tried all manner of changes related to RPATH options and cmake install, but the prefixed path to the library is always remains present. I am stumped and appreciate the help!

Thanks,
-Kelly



More information about the CMake mailing list