Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set RPATH in CMAKE?

Tags:

I wish to build and install a software locally to the $HOME/.local/ path instead of a system-wide /usr/ folder. The software uses CMAKE for compilation.

After installation, the software binaries and libraries get stored in $HOME/.local/bin/ and $HOME/.local/lib/, respectively. However, when I try to run the program, it throws an error that the required library is not found (which, by the way, is present in $HOME/.local/lib/).

The program works fine if I set the $LD_LIBRARY_PATH to $HOME/.local/lib. But I don't want to do this. Hence, instead of this, I would like to know how to specify the RPATH variable (which would point to $HOME/.local/lib) while compiling the software using CMAKE.

Kindly help.

like image 570
Ombrophile Avatar asked Apr 21 '17 20:04

Ombrophile


2 Answers

I am using the following two lines in the CMakefile

set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

(the first one is required only if you use MacOSX)

like image 103
BrunoLevy Avatar answered Oct 16 '22 12:10

BrunoLevy


you may also use:

set(CMAKE_BUILD_RPATH "/my/libs/location")

specifying runtime path (RPATH) entries to add to binaries linked in the build tree (for platforms that support it). The entries will not be used for binaries in the install tree. See also the CMAKE_INSTALL_RPATH variable.

like image 32
Alex B Avatar answered Oct 16 '22 11:10

Alex B