setting rpath in executable in build directory

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

setting rpath in executable in build directory

Jędrzej Dudkiewicz

I have the following scenario. I have gcc 9.2.0 and boost 1.71.0
installed in /opt/ZS/deps/... directory, built for both arm and
x86_64. I can build programs using them just fine and they run as
expected provided -Wl,-rpaht,/opt/ZS/deps... is added to g++ command

Now I'm trying to build  mqtt_cpp library
( using them. Everything builds
just fine using:

export CXX=x86_64-linux-gnu-g++-9.2.0
cmake -G'Unix Makefiles' -S. -Bbuild \
    -DBOOST_ROOT=/opt/ZS/deps/include/ \

This of course does not contain any information regarding RPATH. I
assumed this is why binaries (examples in fact) in build directory
can't find proper libraries, so I tried installing them (examples).
Unfortunately "make install" installs library (it is header-only
library) and not examples, so I can't run any of them.

Since I *really* want to run these examples, I tried configuring and
building using this command:

export CXX=x86_64-linux-gnu-g++-9.2.0
cmake -G'Unix Makefiles' -S. -Bbuild \
    -DBOOST_ROOT=/opt/ZS/deps/include/ \
    -DBOOST_LIBRARYDIR=/opt/ZS/deps/x86_64-linux-gnu/lib/ \

I assumed that -DCMAKE_SKIP_BUILD_RPATH=FALSE means that I want
binaries in build directory (not installed ones) to already have RPATH
I also assumed that -DCMAKE_SKIP_RPATH=OFF assures me that RPATH will
be used during build and/or installation.
I assumed that -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE is supposed to
add to binaries in build directory RPATH containing paths to libraries
found and used by CMake.

All of this simply isn't true, binaries generated by "make -j 4" not
only don't have proper RPATH, they don't have rpath at all, not even
invalid one. I tried with:

readelf -a build/example/broker | grep -i rpath

and using chrpath:

chrpath build/exampl/broker

but there is not even a trace of rpath. Greps comes back emptyhanded
and `chrpath` util informs me, that:

broker: no rpath or runpath tag found

Is there some some magical combination of these flags that allows me
to build and run (this is paramount) binaries that were not installed?

CMake used is 3.15.4, I don't think earlier ones are aware of boost's
version 1.71.0.

I also tried adding -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON , but it
changes nothing.

Thanks in advance,
Jędrzej Dudkiewicz

I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.

Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: