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
Hello,

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
line.

Now I'm trying to build  mqtt_cpp library
(https://github.com/redboltz/mqtt_cpp) 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/ \
    -DBOOST_LIBRARYDIR=/opt/ZS/deps/x86_64-linux-gnu/lib/

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/ \
    -DCMAKE_SKIP_BUILD_RPATH=FALSE \
    -DCMAKE_SKIP_RPATH=OFF \
    -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE

I assumed that -DCMAKE_SKIP_BUILD_RPATH=FALSE means that I want
binaries in build directory (not installed ones) to already have RPATH
embedded.
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 www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

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

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake