6

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.

Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
  • 1
    Very good question, I don't have an answer, would love to hear one. – jv42 Nov 04 '10 at 13:49
  • Don't know the answer either, but C++ can be easily compiled as a *static* binary - it will include all libraries in a single, standalone executable. `g++ -static` – Mikhail Nov 05 '10 at 19:47

3 Answers3

3

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.

Kirk Kelsey
  • 4,259
  • 1
  • 23
  • 26
  • In hind sight, STD C++ may not be the best test case, but it's still worth a shot. – Kirk Kelsey Nov 11 '10 at 00:14
  • 1
    I just realized that OP asked for an environment variable. If the load path is changed to a reference to @rpath, the DYLD_LIBRARY_PATH should be an option. – Kirk Kelsey Nov 11 '10 at 13:23
  • I never got round to verifying this worked, but from what I've learned, it seems like the right answer. – Paul Biggar Nov 27 '11 at 02:00
0

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

jilles
  • 10,509
  • 2
  • 26
  • 39
-1

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

Ryan
  • 16,626
  • 2
  • 23
  • 20
  • As I said in the question, DYLD_LIBRARY_PATH doesn't help. You've answered the question 'How do I set DYLD_LIBRARY_PATH in Xcode', which is not what I asked (not least because I don't use xcode). – Paul Biggar Nov 11 '10 at 15:37
  • That's true. I have had DYLD_LIBRARY_PATH work for me in the past, so my assumption was that you weren't setting up the environment variable correctly in Xcode. I didn't realize you weren't using Xcode. What are you using to build, then? Just curious. Come to think of it, you haven't mentioned how you know that your attempts to load the alternate dylib have been unsuccessful. Can you give a little more information about that? – Ryan Nov 11 '10 at 16:35