[CMake] Weirdness with shared library, RPATH policy on MacOS

Chris Wolf cw10025 at gmail.com
Thu Aug 12 16:37:04 EDT 2010


I have a project which creates a shared library and a utility which uses this
shared library.  I would like to be able to run the utility within the build
tree and also from the final install directory.  I can do this, it works,
but the path hard-coded path in the executable is always the build tree path.

The default RPATH policy works for this:

http://www.cmake.org/Wiki/CMake_RPATH_handling#Default_RPATH_settings

Unfortunately the build directory path gets "baked in" to the executable, 
even at install time.  If I run "make clean", the executable still seems
to find the library even though the copy in the build tree is deleted.  
However, running "otool -L" (same as "ldd" on Linux) on the executable 
reveals that the RPATH is still in the build tree rather then the install path:

$ otool -L lsusb 
lsusb:
	/Users/cwolf/src/cmaketest/libusb-1.0.8/libusb/build/libusb-1.0.dylib (compatibility version 0.0.0, current version 1.0.8)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)


This setting shows which libraries are actually loading at runtime:

$ export DYLD_PRINT_LIBRARIES=true
clozaril-2:bin cwolf$ ./lsusb 
dyld: loaded: /private/tmp/local/bin/./lsusb
dyld: loaded: /tmp/local/lib/libusb-1.0.dylib
dyld: loaded: /usr/lib/libgcc_s.1.dylib
dyld: loaded: /usr/lib/libSystem.B.dylib
dyld: loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
dyld: loaded: /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
[...]


As can be seen, the executable is dynamically linking with the install directory
(/tmp/local/lib)

The preceding is observed regardless of whether I use the default RPATH settings 
or if I use "Always Full RPATH":


http://www.cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH


...which supposedly relinks the executable upon
"make install" such that the RPATH is changed to the install path - but I don't
see that.


Any ideas?  


More information about the CMake mailing list