0

I'm having a problem with cmake, like One of the libraries which I want to link to my shared library which I'm compiling is boost. So, I tried like:

target_link_libraries(my_project
    ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
    ${Boost_CHRONO_LIBRARY}
    ${Boost_DATE_TIME_LIBRARY}
    ${Boost_REGEX_LIBRARY}
    ${Boost_SIGNALS_LIBRARY}
    ${Boost_THREAD_LIBRARY})

However, when I execute in the terminal to check the linkage

    ldd libmy_project.so
    libboost_system.so.1.66.0 => not found
    libboost_chrono.so.1.66.0 => not found
    libboost_date_time.so.1.66.0 => not found
    libboost_regex.so.1.66.0 => not found
    libboost_signals.so.1.66.0 => not found
    libboost_thread.so.1.66.0 => not found

But the boost library was found by the cmake in the CMakeList. Anybody know how to fix this?

Edit:

The problem was to set properly the rpath, I tried to follow the cmake documentation. However, it didn't work for me. The only thing which worked was adding this line before the target_link_libraries(...) in CMkaeLists.txt:

set_target_properties(YOUR_PROJECT PROPERTIES LINK_FLAGS "-Wl,-rpath, YOUR_LIB_LOCATION_HERE")
  • Dynamic loader (`ldd`) uses RPATH mechanism for find libraries. If you have Boost installed not to the *system-default* path, you need to adjust RPATH for find it. See also this question: https://stackoverflow.com/questions/45649565/how-to-make-cmake-embed-library-path-of-imported-target-into-executable. – Tsyvarev May 18 '18 at 09:38
  • Yes, but I'm having some problems to ajust the rpath properly, I still can't link that – Marcelo Duarte Trevisani May 18 '18 at 10:59
  • `but I'm having some problems to ajust the rpath properly` - Then update the question post with a description of what have you tried. – Tsyvarev May 18 '18 at 12:26
  • What's the version of CMake? It has to be 3.11 or newer, cf. https://stackoverflow.com/a/42124857/2799037 – usr1234567 May 18 '18 at 21:36
  • `I tried to follow the cmake documentation. However, it didn't work for me.` - Once again, you say you have problem with your code... but show the **other code**, which works. What is exactly your problem? – Tsyvarev May 18 '18 at 22:32
  • @usr1234567: I don't see why CMake version could be a problem. Configure and build steps has been finished successfully (`libmy_project.so` library has been created). And none "Find" script, including one for Boost, definitely does not operate with RPATH. – Tsyvarev May 18 '18 at 22:33
  • @Tsyvarev Whenever I see recent versions of CMake and no CMake version in the question, there is a high chance to help. Without the CMake version number, the question is incomplete. But in detail, you are right. – usr1234567 May 20 '18 at 12:53
  • I tried with CMake 3.11.1 – Marcelo Duarte Trevisani May 22 '18 at 08:31

0 Answers0