在 OS X 中针对不同的 SDK 运行应用程序?

发布于 2024-09-26 11:58:08 字数 494 浏览 6 评论 0原文

摘要

我想针对 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 技术交流群。

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

发布评论

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

评论(3

浪漫人生路 2024-10-03 11:58:08

使用 install_name_tool 更改路径。如果链接器没有添加填充,您可能无法压缩更长的路径,但您可以使用 rpath 代替。例如,我通过以下操作更改了系统上应用程序的加载路径以使用 10.5 SDK:

install_name_tool -change /usr/lib/libstdc++.6.dylib @rpath/libstdc++.6.dylib /path/to/executable
install_name_tool -add_rpath /Developer/SDKs/MacOSX10.5.sdk/usr/lib /path/to/executable

结果运行良好。我不想做出任何保证,但假设您最初是针对 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:

install_name_tool -change /usr/lib/libstdc++.6.dylib @rpath/libstdc++.6.dylib /path/to/executable
install_name_tool -add_rpath /Developer/SDKs/MacOSX10.5.sdk/usr/lib /path/to/executable

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.

霓裳挽歌倾城醉 2024-10-03 11:58:08

鉴于 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

许你一世情深 2024-10-03 11:58:08

试试这个:

  1. 在 Xcode 中打开您的项目。
  2. 在组中的可执行文件下在“文件”列中,右键单击应用程序的可执行文件并选择“获取信息”
  3. 选择“参数”选项卡
  4. 在窗口下半部分的“要在环境中设置的变量:”下,单击 + 按钮。
  5. 在表中显示的行中,在“名称”下输入 DYLD_LIBRARY_PATH,并在“值”下输入路径(例如 /Developer/SDKs/MacOSX10.5.sdk/usr/lib)。

现在您已经设置了链接路径环境变量。当您从 Xcode 中运行该可执行文件时,将为您设置此环境变量。要测试您的应用程序,只需转到“运行”菜单并选择“运行”。如果您通过直接在 Finder 中双击应用程序来运行该应用程序,则不会为您设置此环境变量。该设置仅在您从 Xcode 运行时生效。

以下是 Apple 关于此过程的文档:

http ://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/XcodeProjectManagement/230-Defining_Executable_Environments/executable_environments.html

Try this:

  1. Open your project in Xcode.
  2. Under Executables in the Groups & Files column, right-click on your application's executable and select Get Info
  3. Select the Arguments tab
  4. In the bottom half of the window, under "Variables to be set in the environment:", click the + button.
  5. In the row that shows up in the table, enter DYLD_LIBRARY_PATH under Name, and enter the path (e.g. /Developer/SDKs/MacOSX10.5.sdk/usr/lib) under Value.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文