如何在OSX上构建(不安装)的cmake中的可执行文件中添加rpath? [英] How do you add an rpath to an executable in cmake on build (not install) on OSX?
问题描述
所以,如果你已经有一个二进制文件,你可以使用'install_name_tool'在OSX上添加一个rpath,如下:
So, if you already have a binary, you can add an rpath to it on OSX using the 'install_name_tool', as so:
install_name_tool -add_rpath @executable_path/blah
xcode会在您建立应用程序包。
xcode does this automatically when you're building an application bundle.
我知道在cmake中你可以使用它来设置共享库的install_name:
I know that in cmake you can use this to set the install_name of the shared library:
set_target_properties(nshared PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")
My question is, what's the equivalent of this to add an rpath to a binary?
(为什么会这样?)我的问题是, 在你们中间,查看你的应用程序/文件夹中的任何应用程序的otool -l,你会看到许多应用程序,如下:
(for the 'why would you do that?' amongst you, go look at the otool -l on any of the apps in your Applications/ folder and you'll see plenty of apps with entries like:
Load command 15
cmd LC_RPATH
cmdsize 36
path @executable_path/../../Frameworks/
这是标准做法。我只是想在cmake中做)
This is standard practice. I'm just trying to do it in cmake)
推荐答案
您可以使用 POST_BUILD命令添加 LC_RPATH
加载命令到构建的可执行文件:
You can use a POST_BUILD command to add an LC_RPATH
load command to the built executable:
add_custom_command(TARGET executable
POST_BUILD COMMAND
${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../../Frameworks/"
$<TARGET_FILE:executable>)
变量 CMAKE_INSTALL_NAME_TOOL
包含在Darwin下的 install_name_tool
可执行文件的路径。
The variable CMAKE_INSTALL_NAME_TOOL
contains the path to the install_name_tool
executable under Darwin.
这篇关于如何在OSX上构建(不安装)的cmake中的可执行文件中添加rpath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!