How can LD_LIBRARY_PATH be changed within CMake?

本小妞迷上赌 提交于 2019-11-30 17:08:59

If your shared lib is not build in the same CMake project of your executable, you can use the CMake rpath handling like this:

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

When you will run make install, CMake will automatically set the runtime path of your executable to your shared library.

If your shared library is built in the same CMake project, use this:

set(CMAKE_INSTALL_RPATH "/usr/local/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

In this case you must add yourself the directory where your shared library will be installed to the runtime path.

For more information, you can read CMake rpath handling

You can set the runtime shared library search path using the -rpath linker option:

SET(CMAKE_EXE_LINKER_FLAGS 
          "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,/usr/local/lib")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!