Mankarse
Mankarse

Reputation: 40613

Link Universal Binary to different dynamic libraries depending on OSX version or processor version

This is actually two questions in one, but I suspect they have similar answers.

I have a program which has a dependency on an X11 library which on OS10.4 has a different name and is in a different place (compared to on 10.5 and 10.6).

This same program also has a dependency on a library which does not work on ppc. This dependency can be removed when compiling for ppc, but I would like to use this library when I can (as it gives speedups of several orders of magnitude).

So the two questions are:

  1. How do I link to a dynamic library which in a different place in different OS versions? Or rephrased - how do I make the dynamic linker load a library from a different place on different OS versions?

  2. How do I make some parts (the Intel parts) of a universal binary link to a library while not having the ppc parts link to that library?

Of course, if there are other solutions to my problems, I am also interested.

Upvotes: 0

Views: 587

Answers (1)

Ted Mielczarek
Ted Mielczarek

Reputation: 3967

The Apple GCC manual mentions -Xarch :

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/gcc.1.html

The documentation for that says

Apply option to the command line for architecture arch.

So presumably you'd want to do something like:

gcc -arch ppc -arch i386 -Xarch ppc -lfoo

If you're building from XCode, you can do this in the Target settings panel. Go to "Other Linker Flags", then click the gear button in the lower left corner of the panel and choose "Add Build Setting Condition", and it will let you specify different linker flags per-architecture.

Upvotes: 1

Related Questions