Xcode: Conditional Build Settings based on architecture (Device (ARM) vs Simulator (i386))

前端 未结 7 1602
陌清茗
陌清茗 2020-12-07 23:22

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 an

相关标签:
7条回答
  • 2020-12-07 23:26

    I had this problem when integrating Adobe Omniture's "AppMeasurement" library, which currently comes compiled for 3 architectures: libAppMeasurement-iOSSimulator.a, libAppMeasurement-iOSDevice.a, and libAppMeasurement-iOSDevice-armv7.a.

    While the other answers here are substantially correct, I ended up having to go elsewhere to truly understand and then fix the problem.

    Step 1. Understanding the issues

    This blog post does a great job of explaining the overall issue. It gives start-to-finish instructions for solving the problem in Xcode 3. See below for Xcode 4.

    Note: You might try skipping the bit where he says to add the static libraries and then delete them. The next time I do this, I'll probably just add the header file(s), then skip straight to editing Other Linker Flags.

    Step 2. Conditional Build Settings in Xcode 4

    This StackOverflow page explains the new way to set conditional build settings in Xcode 4. Tip: The text fields on the Build Settings tab are drag-&-drop enabled; once you have your conditional build setting ready for editing under Other Linker Flags, you can just drag the static library file right onto the text field and Xcode will automatically enter a (hopefully relative) path.

    Here's a screenshot of my Other Linker Flags once I got the "missing required architecture i386" warning to go away with no build errors:

    enter image description here __

    0 讨论(0)
  • 2020-12-07 23:26

    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.

    0 讨论(0)
  • 2020-12-07 23:26

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

    0 讨论(0)
  • 2020-12-07 23:35

    For someone comes across the warning like "[lib_for_sim_or_device] not not built for the architecture ...", the warning arises when dragging the 3rd party library folder into the project.

    Behind the scene the XCode automatically add the library files into 'target setting -> Build Phrases -> Link Binary with Libraries' sections, which causes linking with both libraries.

    To fix that, remove those entries from 'Link Binary with Libraries', and then follow the guide above on conditional building setting for sim/device'

    Hope it helps!

    0 讨论(0)
  • 2020-12-07 23:37

    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.

    0 讨论(0)
  • 2020-12-07 23:37

    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

    0 讨论(0)
提交回复
热议问题