tags:

views:

800

answers:

5

I'm building an iPhone app that has to run on both the simulator and the device. However I'm using an externally compiled library that has one version for the simulator and one for the device (different CPU).

How can I do it? I'm coming from Visual C++ so I'm new to Xcode, and I can't find the way to do it.

+1  A: 

You have 3 options:

  1. If you control click on the name of build setting inside the Inspect Window (where you can change compiler settings, etc) it will bring an option to conditionalize that setting. Just go to the linker flags you want to change, and conditionalize them by SDK, then enter the specific library for each SDK.

  2. Alternatively you can take the library and install it at the same path in each SDKs root ("/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/lib/" and "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/lib"). Since SDK relative library search paths are used the appropriate version will be pulled in for either build.

  3. You can lipo together two libraries into one fat library. That is probably a bad idea, but if you want to do it checkout the manpage.

Louis Gerbarg
A: 

The recommended way to do this is to not add the library to your project and target, but instead to set the Other Linker Flags to include separate, direct references to the link library per configuration.

For Debug:

  OTHER_LINKER_FLAGS = -l/Path/To/My/Debug/Library.dylib

For Release

  OTHER_LINKER_FLAGS = -l/Path/To/My/Release/Library.dylib

You can of course use references to other build settings to make these paths relative to something durable, or use a Source Tree to an external source tree.

cdespinosa
This does not answer the question. The question was about device/simulator, not debug/release. We frequently get two libraries based on the target device/simulator.
zaph
To be fair, Build Setting Conditions didn't exist in July 2009 when I posted my reply, and using Configurations was the only way to do it.
cdespinosa
+1  A: 

For option 1 (see Louis Gerbarg answer) in Xcode 3.2.1 select the "Other Linker Flags" and then select "Add Build Setting Condition" from the dropdown menu at the lower left of the build setting window. See cdespinosa answer for "Other Linker Flags" syntax)

Or you can also "Add Build Setting Condition" to "Library Search Paths" if you have the device/simulator libraries in separate directories.

zaph
A: 

The problem with other linker flags and adding libraries there is controlling the link order of libraries which can be important. It seems that the linker flag version means these libraries will come first so if you are managing other libraries in xcode that have to come first, you then have to abandon that and move everything to the other linker flags...!-P

Peter
A: 

In my XCode 3.2.3, the correct naming seems to be OTHER_LDFLAGS, not OTHER_LINKER_FLAGS.

opyh