2

My C++ executable depends on boost regex which i have imported explicitly. However, during link phase, CMake doesnt use -Wl,-rpath,/path/to/my/boost/lib to embed the rpath in my project executable. How can i acheive that? It does embed rpath to libutils.so, which I also build in my CMakeLists.txt. I am using cmake version 3.9

add_library(boost_regex SHARED IMPORTED GLOBAL)
set_target_properties(boost_regex PROPERTIES IMPORTED_LOCATION ${Boost_REGEX_LIBRARY})

add_library(utils SHARED utils.cpp)
target_link_libraries(utils INTERFACE boost_regex)

add_executable(main main.cpp)
target_link_libraries(main utils)

[100%] Linking CXX executable main cd /home/rajatgirotra/study/cmakeTutorial/sample_ultimate/cmake-build-debug/src/main && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1 /home/rajatgirotra/tools/miniconda2/envs/shriram/bin/c++ -std=c++17 -g CMakeFiles/main.dir/main.cpp.o -o main -Wl,-rpath,/home/rajatgirotra/study/cmakeTutorial/sample_ultimate/cmake-build-debug/src/common ../common/libutils.so /home/rajatgirotra/tools/miniconda2/envs/shriram/lib/libboost_regex.so

Rajat
  • 467
  • 1
  • 5
  • 15
  • rpath and $ORIGIN - See this: https://docs.oracle.com/cd/E19957-01/806-0641/appendixc-16/index.html and this: https://www.google.dk/amp/s/enchildfone.wordpress.com/2010/03/23/a-description-of-rpath-origin-ld_library_path-and-portable-linux-binaries/amp/ – Jesper Juhl Aug 12 '17 at 12:28
  • 1
    Yeah I know about RPATH and $ORIGIN. I am looking for the cmake option/property/command that enables -Wl,-rpath for imported libraries during linking. I am sure there must be something other than manually passing the linker option to "target_link_libraries()" command. – Rajat Aug 12 '17 at 13:26
  • @Rajat did you find a solution for this? From this post it seems impossible.. https://stackoverflow.com/questions/41175354/can-i-install-shared-imported-library/41179630#41179630 – Nibor Sep 19 '17 at 20:47

0 Answers0