6

I am creating package using cmake

I am having following structure

bin/
    bin1
lib/

    lib1
    lib2

Where lib1 and lib2 are external dynamic library. How can I set RPATH so it will automatically link with lib1 and lib2 ?

Vivek Goel
  • 22,942
  • 29
  • 114
  • 186

2 Answers2

6

I've been fussing with cmake on this as well. Cmake uses CMAKE_SKIP_BUILD_RPATH for linking at build time and CMAKE_INSTALL_RPATH to set the rpath used when the install target is built. cmake has some good info on using its rpath mechanism: http://www.cmake.org/Wiki/CMake_RPATH_handling

An alternative method is to use ldconfig. I notice that when you build svn(1.6.17), it's make install target invokes ldconfig to set rpath.

take a look at $ORIGIN as you'll need that in your rpath to keep it relative to the binary rather than relative to $PWD.

Building a simple (hello-world-esque) example of using ld's option -rpath with $ORIGIN

Community
  • 1
  • 1
0

AFAIK, CMake automatically adds rpaths to all targets, which you are linking with target_link_libraries().

To switch it off there is CMAKE_SKIP_RPATH option.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • I don't want to switch it off. I am creating an tar archive. and shipping lib1 and lib2 using custom installed command form cmake. I want to RPATH to be linked relatively to the library. – Vivek Goel Dec 06 '11 at 16:09
  • Ah, i see. Well, i'm even not sure if it's possible to change rpaths on install step, not the build step. By looking at various apps for *NIX that are being distributed in binary form, i can suggest wrapping your executable into shellscript, which would set LD_LIBRARY_PATH before running app. – arrowd Dec 07 '11 at 10:09
  • to 'update' the RPATH you can use https://github.com/NixOS/patchelf which is used for proprietary software and open source as well. – qknight Jan 18 '17 at 13:11