ios 错误:“文件是为存档而构建的,这不是正在链接的体系结构 (armv7s)”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14828693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:15:48  来源:igfitidea点击:

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

iosxcodestatic-librariesarmv7

提问by ThomasCle

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

我已经构建了自己的静态 C++ 库,它是使用以下设置构建的:

  • Architectures: armv7, armv7s
  • Build Active Architectures Only: No
  • Support Platforms: iOS
  • Valid Architectures: armv7, armv7s
  • 架构:armv7、armv7s
  • 仅构建活动架构:否
  • 支持平台:iOS
  • 有效架构: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).

库项目构建良好,我得到了 .a 文件(我已经清理了构建文件夹并再次构建了项目以确保我的设置有效)。

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:

我已将库(.a 文件)添加到我的 iOS 项目中,但即使我在 iOS 项目上设置了完全相同的设置,该项目也不会构建:

  • Architectures: armv7s, armv7
  • Build Active Architectures Only: Yes
  • Support Platforms: iOS
  • Valid Architectures: armv7, armv7s
  • 架构:armv7s、armv7
  • 仅构建活动架构:是
  • 支持平台:iOS
  • 有效架构: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

ld: 警告: 忽略文件/Users/hidden/Library/Developer/Xcode/DerivedData/HelloWorldCppLib-fomvvtklwijvqicyhahxleiscein/Build/Products/Debug-iphoneos/libHelloWorldCppLib.a,文件是为存档构建的,这不是被链接的架构 (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.

我错过了什么?它告诉我 .a 文件不是为 armv7s 构建的,但这正是我构建库所用的设置。

采纳答案by graver

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.

在构建库时,您必须为模拟器和设备编译它,然后将两个输出(.a 文件)合并到 1 个库中,然后将其链接到您的 iOS 项目。

回答by Buzzy

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

我自己也遇到了类似的问题。@graver的解决方案绝对有效。

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

问题是该库是为armv7而不是armv7s. 您可以使用 自行验证这一点lipo <path/to/lib.a> -info

Setting the Build Active Architectures Onlyoption to Nofixes the issue.

设置Build Active Architectures Only选项以No解决问题。

Hope this helps.

希望这可以帮助。

回答by lbsweek

one additional notes is:

另一项说明是:

    Build Active Architectures Only  set to no

is for the lib project.

用于 lib 项目。

回答by Kevin ABRIOUX

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.

使用 cocapods 时,我遇到了完全相同的错误:对我来说,解决方案是为目标和 pod 使用两种不同的构建活动架构。

App Target :

应用目标:

Build Active Architectures Only  **Yes**

pods Target

豆荚目标

Build Active Architectures Only  **No**

回答by Alexey Ishkov

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.

不幸的是,所有这些建议对我都不起作用 - Xcode 7.3.1 (7D1014)、iPhone 5。但是一旦我删除了所有 Xcode 临时文件(+ 重新启动 Xcode)并再次重建它就可以工作了。

回答by Nicolas Buquet

It did happen to me with Facebook SDK (v 4.24.0) used via CocoaPods.

通过 CocoaPods 使用 Facebook SDK (v 4.24.0) 确实发生在我身上。

Cleanning or setting Build Active Architectures Onlyto NOon Pods didn't resolve the problem.

在 Pod 上清洁或设置Build Active Architectures OnlyNO无法解决问题。

The solution was to empty the build directory (see Build settings/Build locations/CONFIGURATION_BUILD_DIR) OR $(CONFIGURATION_BUILD_DIR)Xcode variable.

解决方案是清空构建目录(请参阅构建设置/构建位置/CONFIGURATION_BUILD_DIR)或$(CONFIGURATION_BUILD_DIR)Xcode 变量。

回答by boto

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.

我使用 XCode 5.1.1 并遇到了所描述的问题。解决这个问题的更方便的方法似乎只是创建一个存档(通过菜单 Build/Archive)并分发它。分布式 lib 文件将包含所有定义的架构。