0

I'm trying to make my first roject using Cmake and I'm faced with issue with static linking to *.so library.

My binary see libraries only from the build folder.

I've tried to use this statements from "RPATH handling" manual, but it's not working so far:

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
target_link_libraries(mt libjack.so "${CMAKE_BINARY_DIR}/lib/librtmidi.so")

With qmake in comparison, I can just include this to pro file:

QMAKE_LFLAGS += -Wl,--rpath=\\\$\$ORIGIN/lib

and then, no matter, where I will deploy my binary to, one will be linked to library in /lib folder.

Thank you!

Demetera
  • 53
  • 1
  • 8
  • 1
    `CMAKE_INSTALL_RPATH` and other CMake variables, which affects on RPATH, should be set **before** creation of the target (`add_executable`), not *after* it. See e.g. [that answer](https://stackoverflow.com/a/44165347/3440745). – Tsyvarev Feb 07 '21 at 15:29

1 Answers1

1

With the help of Tsyvarev, I've managed to make my binary linked statically with lib folder no matter, where I copying them. For CMAKE_INSTALL_RPATH I put "lib" (instead of "/lib") Placed this block before add_executable definition

...
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
...
add_executable(mtest main.cpp)
...
target_link_libraries(mtest libjack.so "${CMAKE_BINARY_DIR}/lib/librtmidi.so")
...

Thank you!

Demetera
  • 53
  • 1
  • 8