开发者

Running applications against a different SDK in OS X?

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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜