Search code examples
iosxcodestatic-librariesarmv7

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


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.


Solution

  • 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.