Search code examples
iosxcodeios-simulatorstatic-linking

Xcode error: file was built for archive which is not the architecture being linked (x86_64)


I have a iOS Xcode project that builds and runs fine in Simulator and device. However, I have a new feature that requires using a static library (built for ARM architecture only) - which means that it builds & runs fine on device but for simulator I get this error -

ld: warning: ignoring file libXYZ.a, file was built for archive which is not the architecture being linked (x86_64): libXYZ.a

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_XYXClass", referenced from: objc-class-ref in MyAppClass.o

I understand the issue but I still want to be able to build & run the app in Simulator (perhaps by excluding or disabling the new feature in Simulator which requires the static library).

I have tried the following project settings so that the app can build for Simulator as well -

  1. Setting 'Architectures' to $(ARCHS_STANDARD_INCLUDING_64_BIT)
  2. Setting 'Build Active Architectures only' to NO

Nothing has worked. Any thoughts how I can build for Simulator? Thanks!


Solution

  • The easiest solution is probably just build the static archive with intel slices (against the iOS Simulator SDK) in addition to the arm ones such that it is 4-way fat (i386+x86_64/iOS Simualtor and armv7/arm64/iOS).

    If that is not possible, please explain why that is not possible for you and file a radar at http://bugreport.apple.com, so we can address whatever problem is preventing you from building your static archive.

    If you want to proceed without using the static archive in the iOS Simulator build, you will need to avoid using the XYXClass in the simulator. You can do this by doing something like:

    #include <TargetConditionals.h>
    #if TARGET_IPHONE_SIMULATOR
        // Do sim-specific fallbacks
    #else
        // Do stuff with XYXClass
    #endif
    

    Note that the "warning: ignoring file libXYZ.a ..." message is not fatal. It's just a warning that you can ignore. The fatal part is your use of the XYXClass which doesn't have an implementation in x86_64.