RPATH for Dummies

2 minute read.

This is the blog post I wish I had 5 hours ago, here to hope­ful­ly save some­one else some time.


Mac­OS al­lows em­bed­ding paths to de­pen­den­cies to shared li­braries in ex­e­cuta­bles and shared li­braries.

List paths with:

otool -L <path-to-the-binary>

Mod­i­fy the rpath with:

install_name_tool -change <old-path> <new-path> <path-to-the-binary>

-change will keep pos­si­ble oth­er meta­da­ta for ver­sion range, which would oth­er­wise be re­moved with install_name_tool -delete_rpath <old-path> -add_rpath <new-path> <path-to-the-binary>.

Ad­di­tion­al­ly the ex­e­cutable can con­tain a list of “run paths”/rpaths, that are searched if the path to a shared li­brary con­tains @rpath.

Spe­cial: @load­er_­path, @rpath, @ex­e­cutable_­path

Sum­ma­riz­ing this won­der­ful blog post: “@ex­e­cutable path, @load path and @rpath” 1

@loader_path spec­i­fies the path of the load­ing bi­na­ry (ex­e­cutable or shared li­brary).

@executable_path spec­i­fies the path of the load­ing ex­e­cutable.

@rpath tells the run­time link­er to search the “rpath”, which is a list of search paths em­bed­ded in the ex­e­cutable.


CMake has two sets of run paths: INSTALL_RPATH and BUILD_RPATH. For run­ning bi­na­ries from the build di­rec­to­ry, BUILD_RPATH is used while the install tar­get will mod­i­fy the ex­e­cutable and shared li­brary rpaths to use INSTALL_RPATH.

You can over­ride these with CMAKE_INSTALL_RPATH 2 and CMAKE_BUILD_RPATH 3.

See al­so “RPATH Han­dling” doc­u­men­ta­tion of CMake 4.

“@ex­e­cutable path, @load path and @rpath” Blog Post
RPATH Han­dling