如何在CMake中更改LD_LIBRARY_PATH? [英] How can LD_LIBRARY_PATH be changed within CMake?

查看:4745
本文介绍了如何在CMake中更改LD_LIBRARY_PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地共享库,不在$ LD_LIBRARY_PATH。
我想运行我的可执行文件,但由于它无法在系统文件夹中找到共享库,它会输出加载共享库时出错。

I have a local shared library which is not in $LD_LIBRARY_PATH. I want to run my executable, but since it cannot find the shared library in the system folders, it outputs "error while loading shared libraries".

A可能的修复是导出包含本地库文件夹的新LD_LIBRARY_PATH。

A possible fix for this is to export a new LD_LIBRARY_PATH containing the local library folder.

如何自动导出CMake中的这个环境变量?

How can I export automatically this environment variable within CMake?

推荐答案

如果您的共享库不是在可执行文件的同一个CMake项目中构建,您可以使用CMake rpath处理,如下所示:

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)

当您将运行 make install 时,CMake会自动将您的可执行文件的运行时路径设置为您的共享库。

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

如果您的共享库是在同一个CMake项目中构建,请使用:

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.

有关详细信息,请参阅 CMake rpath处理

For more information, you can read CMake rpath handling

这篇关于如何在CMake中更改LD_LIBRARY_PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆