Error: "File was built for archive which is not the architecture being linked (armv7s)"

35,200

Solution 1

When you're building a library you must compile it both for the simulator and the device and then merge the two outputs (.a files) into 1 library and then link it to your iOS project.

Solution 2

I ran into a similar problem myself. @graver's solution is definitely valid.

The issue was that the library was being built for armv7 instead of armv7s. You can verify this yourself by using lipo <path/to/lib.a> -info.

Setting the Build Active Architectures Only option to No fixes the issue.

Hope this helps.

Solution 3

one additional notes is:

    Build Active Architectures Only  set to no

is for the lib project.

Solution 4

I have got the exact same error when with cocapods : For me the solution was to have two differents Build Active Architecture for target and pods.

App Target :

Build Active Architectures Only  **Yes**

pods Target

Build Active Architectures Only  **No**

Solution 5

unfortunately all these pieces of advice don't work for me - Xcode 7.3.1 (7D1014), iPhone 5. but as soon as I removed all Xcode temporary files (+ restart Xcode) and rebuild again it became working.

Share:
35,200
ThomasCle
Author by

ThomasCle

Updated on July 09, 2022

Comments

  • ThomasCle
    ThomasCle almost 2 years

    I have built my own Static C++ Library, which is built with the settings:

    • Architectures: armv7, armv7s
    • Build Active Architectures Only: No
    • Support Platforms: iOS
    • Valid Architectures: armv7, armv7s

    The library project builds well and I got the .a file (I have cleaned the build folder and built the project again to be sure my settings were effective).

    I have added the library (.a file) to my iOS project, but the project won't build even though I have set the exact same settings on the iOS project:

    • Architectures: armv7s, armv7
    • Build Active Architectures Only: Yes
    • Support Platforms: iOS
    • Valid Architectures: armv7, armv7s

    I keep getting this error:

    ld: warning: ignoring file /Users/hidden/Library/Developer/Xcode/DerivedData/HelloWorldCppLib-fomvvtklwijvqicyhahxleiscein/Build/Products/Debug-iphoneos/libHelloWorldCppLib.a, file was built for archive which is not the architecture being linked (armv7s): /Users/hidden/Library/Developer/Xcode/DerivedData/HelloWorldCppLib-fomvvtklwijvqicyhahxleiscein/Build/Products/Debug-iphoneos/libHelloWorldCppLib.a

    What am I missing? It tells me the .a file was not built for armv7s, but that is exactly the settings I built the library with.

  • ThomasCle
    ThomasCle over 11 years
    That did the trick! I ran this in the terminal: lipo -create libHelloWorldCppLibPhone.a libHelloWorldCppLibSimulator.a -output libHelloWorldCppLib.a and imported the merged result to my iOS project.
  • Mustafa
    Mustafa almost 11 years
    @ThomasCle Thanks for sharing this awesome tip!
  • ThomasCle
    ThomasCle over 10 years
    I have created a script to simplify the merging process: cupcakecoding.com/coding/…
  • Yoga
    Yoga about 10 years
    This worked for me! I'm still not sure why I need to compile it for both simulator and device when I only intend to run it on the device. Anyone any ideas?
  • Jinbom Heo
    Jinbom Heo about 10 years
    Thanks! Library's 'Build Active Architectures' Release was YES, debug was NO. to YES fixed it.
  • emotality
    emotality about 10 years
    Thank you Thomas this worked perfectly, saved me! :)
  • user1105951
    user1105951 almost 10 years
    thanks. that was my problem when updating SDWebImage library
  • Yuri Brigance
    Yuri Brigance almost 8 years
    This solved a problem that other solutions didn't 👍
  • jayant rawat
    jayant rawat over 7 years
    it works wonderfully...cocoapods always come with new issues like this..
  • Ryan Gross
    Ryan Gross almost 7 years
    Note that this is in addition to everything shown in other solutions. Worked for me on a cocoapods issue.
  • Native_Mobile_Arch_Dev
    Native_Mobile_Arch_Dev almost 7 years
    Thanks! Worked like a charm.