如何正确设置运行路径,搜索路径和安装名称? [英] How to properly set run paths, search paths, and install names?

查看:126
本文介绍了如何正确设置运行路径,搜索路径和安装名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些项目正在编译为动态库.这些.dylib中的每一个都依赖于我想放置在其他目录中的其他各种.dylib(即,某些位于可执行文件路径,某些位于加载程序路径,某些位于固定路径).

I have a collection of projects that I'm compiling as dynamic libraries. Each of these .dylibs depend on other various .dylibs that I would like to place in various other directories (i.e. some at the executable path, some at the loader path, some at a fixed path).

当我在已编译的库上运行otool -L时,会获得这些依赖项的路径列表,但是我知道如何设置/确定这些路径.它们几乎是伪随机的.我已经花了几个小时弄乱Xcode中的构建设置"来尝试更改这些路径(带有@ rpath,@ executable_path,@ loader_path等),但是我似乎无法更改任何内容(通过运行otool -L).我什至不能完全确定在何处添加这些标志,也不太了解以下内容之间的区别或如何正确使用它们:

When I run otool -L on the compiled libraries, I get a list of paths to those dependencies but I have know idea how those paths are being set/determined. They almost appear pseudo random. I've spent hours messing with the "Build Settings" in Xcode to try and change these paths (w/ @rpath, @executable_path, @loader_path, etc.) but I can't seem to change anything (as checked by running otool -L). I'm not even entirely sure where to add these flags and don't really understand the difference between the following or how to properly use them:

链接-动态库安装名称"
链接-运行路径搜索路径"
链接-其他链接标志"
搜索路径-图书馆搜索路径"

Linking - "Dynamic Library Install Name"
Linking - "Runpath Search Paths"
Linking - "Other Linking Flags"
Search Paths - "Library Search Paths"

当我在各种库上运行install_name_tool -change时,我能够成功更改运行路径搜索路径(再次通过运行otool -L进行确认以确认).

When I run install_name_tool -change on the various libraries, I am able to successfully change the run path search paths (again as verified by running otool -L to confirm).

我正在运行Xcode 4.2,非常接近放弃,只是使用运行install_tool_name的构建后脚本进行更改.但这是一个糟糕的骇客修复程序,我不愿意这样做.

I'm running Xcode 4.2 and I'm very close to giving up and just using a post-build script that runs install_tool_name to make the changes. But its a kludge hack fix and I'd prefer not to do it.

在哪里可以看到如何设置dylib依赖项的搜索/运行路径?
有人对我可能做错了什么有什么想法?

Where can I see how the search/run paths for the dylib dependencies are being set?
Anyone have any ideas on what I might be doing wrong?

推荐答案

通常,在我的dylib目标中,我将INSTALL_PATH aka安装目录"设置为所需的前缀(例如@executable_path/../Frameworks).

Typically, in my dylib's target, I set INSTALL_PATH aka "Installation Directory" to the prefix I want (e.g. @executable_path/../Frameworks).

我将LD_DYLIB_INSTALL_NAME又名动态库安装名称"设置为默认值,即$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH).

I leave LD_DYLIB_INSTALL_NAME aka "Dynamic Library Install Name" set to its default value, which is $(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH).

Xcode会根据目标的名称对其进行扩展,例如,它最终可能会以@executable_path/../Frameworks/MyFramework.framework/Versions/A/MyFramework结尾.

Xcode expands that based on your target's name, so it might end up being @executable_path/../Frameworks/MyFramework.framework/Versions/A/MyFramework, for instance.

要意识到的重要一点是,安装路径是在dylib中内置的,这是其构建过程的一部分.稍后,当您链接指向A.dylib的B.dylib时,A.dylib的安装路径被复制到 B.dylib. (这就是otool向您显示的-那些复制的安装路径.)因此,最好首先将正确的安装路径内置到dylib中.

The important thing to realize is that the install path is built into the dylib, as part of its build process. Later on, when you link B.dylib that refers to A.dylib, A.dylib's install path is copied into B.dylib. (That's what otool is showing you -- those copied install paths.) So it's best to get the correct install path built into the dylib in the first place.

在尝试使所有dylib一起工作之前,请分别检查每个.构建它,然后在构建的dylib上otool -L.每种架构的第一行应该是LD_DYLIB_INSTALL_NAME向您展示的内容.

Before trying to get all the dylibs working together, check each one individually. Build it, then otool -L on the built dylib. The first line for each architecture should be what LD_DYLIB_INSTALL_NAME was showing you.

一旦组织好了,请尝试使dylib相互链接.它应该简单得多.

Once you have that organized, try to get the dylibs linking against each other. It should be much more straightforward.

这篇关于如何正确设置运行路径,搜索路径和安装名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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