在 OS X 中针对不同的 SDK 运行应用程序?
摘要
我想针对 10.5 库运行交叉编译的应用程序。是否有一个环境变量可以让它工作?
较长版本
我在 10.6 主机上针对 10.5 目标交叉编译了我的 OS X C++ 应用程序。它编译得很好。编译后的应用程序链接到 /usr/lib/libstdc++.6.dylib
等库。当我在我的系统上运行它时,它将使用“主机”版本的库,即 10.6。我想针对 10.5 版本对其进行测试,这些版本都包含在 `/Developer/SDKs/MacOSX10.5.sdk 目录中。我该怎么做?
我尝试了各种风格的 DYLD_LIBRARY_PATH、DYLD_ROOT_PATH 等,如 记录在手册中,但我还没有设法让它工作。
Summary
I want to run my cross-compiled application against the 10.5 libraries. Is there an environmental variable that allows this to work?
Longer version
I cross-compiled my OS X C++ application for a 10.5 target, on a 10.6 host. It compiles fine. The compiled application is linked against libraries like /usr/lib/libstdc++.6.dylib
. When I run it on my system, it will use the 'host' version of libraries, which are 10.6. I'd like to test it against the 10.5 versions, which are all contained in the `/Developer/SDKs/MacOSX10.5.sdk directory. How do I do this?
I tried various flavours of DYLD_LIBRARY_PATH, DYLD_ROOT_PATH, etc, as documented in the manual, but I haven't managed to get it working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 install_name_tool 更改路径。如果链接器没有添加填充,您可能无法压缩更长的路径,但您可以使用 rpath 代替。例如,我通过以下操作更改了系统上应用程序的加载路径以使用 10.5 SDK:
结果运行良好。我不想做出任何保证,但假设您最初是针对 10.5 SDK 进行编译的,那么您就有机会了。
如果您需要查看可执行文件正在使用的路径,
otool -L
将列出它们。Use install_name_tool to change the path. You may not be able to squeeze in a longer path if the linker didn't add padding, but you can use an rpath instead. For example, I changing the load path for an app on my system to use the 10.5 SDK by doing:
and it ran fine after the fact. I wouldn't want to make any assurances, but assuming you compiled against the 10.5 SDK initially, you've got a shot.
If you need to see the paths the executable is using,
otool -L
will list them.鉴于 OS X 没有稳定的内核 ABI,这种情况不太可能发生。相反,稳定的 ABI 是由系统库提供的。因此,使用与内核版本不同的系统库可能会崩溃。 (我不知道它破坏到什么程度。)
请参阅 http:// /developer.apple.com/library/mac/#qa/qa2001/qa1118.html
It is unlikely that this is possible, given that OS X does not have a stable kernel ABI. Instead, the stable ABI is the one provided by the system libraries. Therefore, using system libraries of a different version than the kernel may break. (I do not know to what degree it breaks.)
See http://developer.apple.com/library/mac/#qa/qa2001/qa1118.html
试试这个:
现在您已经设置了链接路径环境变量。当您从 Xcode 中运行该可执行文件时,将为您设置此环境变量。要测试您的应用程序,只需转到“运行”菜单并选择“运行”。如果您通过直接在 Finder 中双击应用程序来运行该应用程序,则不会为您设置此环境变量。该设置仅在您从 Xcode 运行时生效。
以下是 Apple 关于此过程的文档:
http ://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/XcodeProjectManagement/230-Defining_Executable_Environments/executable_environments.html
Try this:
Now you've got your link path environment variable set up. This environment variable will be set for you when you run that executable from within Xcode. To test your app, just go to the Run menu and select "Run". If you run the app by double-clicking it directly in the Finder, you won't get this environment variable set for you. The setting only takes effect when you run from Xcode.
Here's Apple's documentation on this process:
http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/XcodeProjectManagement/230-Defining_Executable_Environments/executable_environments.html