Error: “File was built for archive which is not th

2019-01-30 14:37发布

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.

7条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-30 14:51

one additional notes is:

    Build Active Architectures Only  set to no

is for the lib project.

查看更多
Melony?
3楼-- · 2019-01-30 14:59

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.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-30 15:00

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**
查看更多
倾城 Initia
5楼-- · 2019-01-30 15:06

I use XCode 5.1.1 and ran into the described problem. A more convenient way to solve this problem seems to be just to create an Archive (via menu Build/Archive) and distribute it. The distributed lib file will contain all defined architectures.

查看更多
走好不送
6楼-- · 2019-01-30 15:08

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.

查看更多
三岁会撩人
7楼-- · 2019-01-30 15:11

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.

查看更多
登录 后发表回答