使用 CMake 创建二进制文件会删除运行时路径

发布于 2024-09-11 22:56:32 字数 580 浏览 7 评论 0原文

我正在使用 CMake 在 Linux 上构建程序。程序编译成功并从项目构建目录运行。该程序与目录 ${HOME}/build/lib 中的自定义库链接,

我有一个安装阶段:

install(TARGETS ProgName RUNTIME DESTINATION bin)

当我运行 make install 时,程序将被放入正确的位置,但 cmake 安装程序从二进制文件中删除了运行时路径。

-- Install configuration: "Debug"
-- Installing: *binary name*
-- Removed runtime path from "*binary name*"

我在互联网上阅读过讨论 LD_LIBRARY_PATH 变量滥用的文章,因此如果可能的话,我希望将我的变量限制在系统库位置。我不是系统管理员,因此我也无法将该位置添加到默认链接器搜索路径。

有谁知道如何在安装或至少自定义将哪些路径添加到运行时时保留开发时链接路径?

干杯

I am using CMake to build a program on linux. The program compiles successfully and runs from the project build directory. The program is linked with a custom library in the directory ${HOME}/build/lib

I have an install stage with:

install(TARGETS ProgName RUNTIME DESTINATION bin)

When I run make install the program gets put in the correct place, but the cmake installer removes the runtime path from the binary.

-- Install configuration: "Debug"
-- Installing: *binary name*
-- Removed runtime path from "*binary name*"

I have read articles on the internet discussing the misuse of the LD_LIBRARY_PATH variable so I like to keep mine limited to system library locations if possible. I am not sysadmin so I cannot add the location to the default linker search path either.

Does anyone know how I can keep the development-time linking paths when installing or at least customising which paths are added to the runtime?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眸中客 2024-09-18 22:56:32

注意:如果您不想修改 cmake 脚本本身,请设置属性,您可以使用要求不删除运行时路径的指令来启动 cmake:< br>
请参阅“控制构建的变量”,其中包含变量:“CMAKE_SKIP_RPATH

如果为 true,则不添加运行时路径信息。

如果设置为 TRUE,则 rpath 信息不会添加到已编译的可执行文件中。
如果平台支持,默认会添加rpath信息。这允许从构建树轻松运行。
要在安装步骤中省略 RPATH,但不在构建步骤中省略,请改用 CMAKE_SKIP_INSTALL_RPATH

如果交付已经包含正确的运行时路径,则该指令将避免 cmake 对所述交付中包含的当前运行时路径进行任何修改。

cmake -DCMAKE_SKIP_RPATH=ON xxx.cmake

Note: if you don't want to modify the cmake scripts themselves, setting property around, you can launch you cmake with a directive asking to not remove the runtime path:
See "Variables that Control the Build", with variable: "CMAKE_SKIP_RPATH"

If true, do not add run time path information.

If this is set to TRUE, then the rpath information is not added to compiled executables.
The default is to add rpath information if the platform supports it. This allows for easy running from the build tree.
To omit RPATH in the install step, but not the build step, use CMAKE_SKIP_INSTALL_RPATH instead.

If the deliveries already contained the right runtime path, that directive will avoid cmake to do any modification to the current runtime path included in said deliveries.

cmake -DCMAKE_SKIP_RPATH=ON xxx.cmake
薄情伤 2024-09-18 22:56:32

您应该查看 set_target_properties 命令和属性 BUILD_WITH_INSTALL_RPATH

http ://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties

You should look at set_target_properties command and the property BUILD_WITH_INSTALL_RPATH

http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set_target_properties

情徒 2024-09-18 22:56:32

这适用于 CMake 2.8,

 set_target_properties(foo PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

其中 foo 是您之前定义的目标:

 project(foo)
 add_executable(foo ...)
  ...
 install(TARGETS foo DESTINATION bin)
  ...

之前

% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Removed runtime path from "/opt/mystuff/bin/foo"

之后

% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Set runtime path of "/opt/mystuff/bin/foo" to "/opt/zzyzx/lib:/opt/bar/lib/x86_64"

This works for CMake 2.8

 set_target_properties(foo PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

where foo is the target you defined earlier:

 project(foo)
 add_executable(foo ...)
  ...
 install(TARGETS foo DESTINATION bin)
  ...

Before

% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Removed runtime path from "/opt/mystuff/bin/foo"

After

% sudo make install
Install the project...
-- Install configuration: ""
-- Installing: /opt/mystuff/bin/foo
-- Set runtime path of "/opt/mystuff/bin/foo" to "/opt/zzyzx/lib:/opt/bar/lib/x86_64"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文