[CMake] MacOS X RPATH

clinton at elemtech.com clinton at elemtech.com
Thu Jul 11 12:33:37 EDT 2013


----- Original Message -----
> Hi,
> 
> Using the following RPATH commands, my project is working fine on Linux and
> OS X.
> 
>  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
>   set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
>   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
> 
> Now, I have the need to link to a library that is outside the system paths
> and has to reside, e.g. at /home/user/foo.
> Keeping the above three lines , everything on Linux still works fine. The
> path to /home/user/foo/libfoo is added to the executable, as it should,
> because of the
> set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
> line.
> 
> But in OS X , while everything links fine and compiles fine, the binaries
> cannot find the new library, and a quick look with otool reveals that the
> path was not set for libfoo and I have to manually copy it to the
> executable's location in order to work.
> 
> Any ideas?

OS X and Linux behave differently when it comes to searching for dependent libraries.
The following blog explains how it works on Mac OS X, and if you are looking for similar behavior, it explains how to get that with a new feature in the next cmake release.
http://www.kitware.com/blog/home/post/510

With the new feature, you can avoid copying libfoo, if it uses @rpath in its install name.

Clint


More information about the CMake mailing list