ios 文件是为存档构建的,这不是被链接的架构(i386)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10803211/
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 18:32:55  来源:igfitidea点击:

file was built for archive which is not the architecture being linked (i386)

iosiphonexcodeipadlinker-errors

提问by yarlg

I got to build static library. I want to use in my iPhone and ipad app. When I try to run the simulator I get linking errrors. I am new to iOS development. kindly help;

我必须构建静态库。我想在我的 iPhone 和 ipad 应用程序中使用。当我尝试运行模拟器时,出现链接错误。我是 iOS 开发的新手。善意的帮助;

ld: warning: ignoring file /Users/valuelabs/Desktop/DruvaProject/libraries/libnetUtils.a, file was built for archive which is not the architecture being linked (i386) Undefined symbols for architecture i386:
"_OBJC_CLASS_$_netUtils", referenced from: objc-class-ref in ViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld:警告:忽略文件 /Users/valuelabs/Desktop/DruvaProject/libraries/libnetUtils.a,文件是为归档而构建的,这不是被链接的架构 (i386) 架构 i386 的未定义符号:
“_OBJC_CLASS_$_netUtils”,引用自:ViewController.o ld 中的 objc-class-ref:未找到架构 i386 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

I tried adding i386 in the Architectures. but no luck

我尝试在架构中添加 i386。但没有运气

采纳答案by Cody A. Ray

After struggling with this same problem and following all the accepted answers of updating build settings, clearing the linker search path, etc.. I finally discovered an answer that worked for me.

在解决了同样的问题并遵循了更新构建设置、清除链接器搜索路径等所有公认的答案之后……我终于找到了一个对我有用的答案。

Before building, make sure you select right type (iPhone Simulator) instead of iOS Device. Then rebuild. Otherwise, you're trying to use a library built for an iOS device (arm processor) on a simulator on your mac (i386). Should've been obvious, but wasn't.

在构建之前,请确保选择正确的类型(iPhone 模拟器)而不是 iOS 设备。然后重建。否则,您会尝试在 Mac (i386) 上的模拟器上使用为 iOS 设备(arm 处理器)构建的库。应该很明显,但不是。

Before:

前:

iOS Device Settings

iOS 设备设置

After:

后:

iPhone 5.1 Simulator Settings

iPhone 5.1 模拟器设置

Now, look in the Products group in the Navigator > right click your static library (.a file) > Show in Finder, you'll notice that its in a Debug-iphonesimulator folder instead of Debug-iphoneos. I didn't pay any attention to the folder name originally, or I might have thought of this sooner.

现在,查看导航器中的产品组 > 右键单击​​您的静态库(.a 文件)> 在 Finder 中显示,您会注意到它位于 Debug-iphonesimulator 文件夹中,而不是 Debug-iphoneos。原来我没注意文件夹名,不然我可能早想到了。

Hope this helps.

希望这可以帮助。

回答by Gajendra K Chauhan

Sometimes these types of errors irritates you!

有时这些类型的错误会激怒你!

Removing Derived Data Works for me:

删除派生数据对我有用:

Steps to fix

修复步骤

1) In XCODE > Windows > Project > Select your project > Delete derived Data > Quit XCODE and Reopen it > If you get MAC-O-Linker builed failed error > Refere thislink > Clean and Build again.

1) 在 XCODE > Windows > 项目 > 选择您的项目 > 删除派生数据 > 退出 XCODE 并重新打开它 > 如果您收到 MAC-O-Linker构建失败错误 > 请参阅链接 > 再次清理和构建。

回答by achow

Your libnetUtils.ais being built for a different architecture than your target.

libnetUtils.a正在为与目标不同的架构而构建。

Check the libnetUtils build settings. The architectures that it is being built for and its list of supported architectures must be a (weak) superset of your target's architecture. The complexity here is that the resulting architecture is spread over various settings: "Architectures", "Build active architecture only" and "Valid Architectures".

检查 libnetUtils 构建设置。为其构建的体系结构及其支持的体系结构列表必须是目标体系结构的(弱)超集。这里的复杂性在于生成的架构分布在各种设置中:“架构”、“仅构建活动架构”和“有效架构”。

"Build active architecture only" settings make this particularly confusing. For example, suppose you are building for the simulator. If the "Build active architecture only" setting for Debug is set to NO, it will be building all the architectures listed in "Architectures" and "Valid architectures" (probably armv7, etc). But if libnetUtils has that setting set to Yes (Debug: Yes) it is only building for i386. So when your linker tries to link armv7 with i386, it fails.

“仅构建活动架构”设置使这特别令人困惑。例如,假设您正在为模拟器构建。如果“构建有源体系仅”为调试设置为NO,将全部建设在“架构”和“有效的架构”(可能的ARMv7等)中列出的架构。但是,如果 libnetUtils 将该设置设置为 Yes (Debug: Yes),则它仅针对 i386 构建。因此,当您的链接器尝试将 armv7 与 i386 链接时,它会失败。

回答by Kiran

If I get the ignore file warning - I would run lipo -infoon ignored file to find it's architecture as below

如果我收到忽略文件警告 - 我会lipo -info在被忽略的文件上运行以找到它的架构,如下所示

lipo -info libnetUtils.a

That would print either of i386, armv6, armv7, armv7s, x86_64 etc. In general, that architecture has to match with your target build platform. E.g.

这将是打印的I386,ARMv6的,ARMv7的,armv7s,x86_64的等。在一般情况下,该架构具有以配合您的目标构建平台。例如

  • i386 = ios simulator or 32 bit build on mac os x
  • armv6 armv7 arm7s = ios device
  • x86_64 = 64 bit build on mac os x
  • i386 = ios 模拟器或 mac os x 上的 32 位构建
  • armv6 armv7 arm7s = ios 设备
  • x86_64 = 64 位构建于 mac os x

Depending on the mismatch, either you have to rebuild your library for your target platform or change your target platform.

根据不匹配,您必须为目标平台重建库或更改目标平台。

Note: For fat binaries, lipo -infowill print a combination of above architectures.

注意:对于胖二进制文件,lipo -info将打印上述架构的组合。

回答by Alexander Bekert

I don't actually know if my advice is correct, but try checking this:

我实际上不知道我的建议是否正确,但请尝试检查以下内容:

  • Select your project
  • Select "Build Settings"
  • Check Architectures:
    • Valid architectures should be "armv6 armv7"
    • Supported platforms should be "iphonesimulator iphoneos" (maybe iPad, I don't know)
    • Base SDK – your iOS SDK (I have iOS 5.0).
  • 选择您的项目
  • 选择“构建设置”
  • 检查架构:
    • 有效的架构应该是“armv6 armv7”
    • 支持的平台应该是“iphonesimulator iphoneos”(也许是 iPad,我不知道)
    • Base SDK – 你的 iOS SDK(我有 iOS 5.0)。

Do not judge me if I am captain obvious :)

如果我是明显的队长,请不要评判我:)

回答by CodaFi

It means the library you are trying to use was not universally compiled for the iOS simulator (i386 symbols are for the Mac). Running it on an actual device should work fine though.

这意味着您尝试使用的库并未针对 iOS 模拟器进行普遍编译(i386 符号适用于 Mac)。不过,在实际设备上运行它应该可以正常工作。

回答by Eino Gourdin

Had the same problem, and tried diverse solutions from the page to no avail. I still had a message telling me my library was not build for arm64.

遇到了同样的问题,从页面尝试了各种解决方案都无济于事。我仍然收到一条消息,告诉我我的库不是为 arm64 构建的。

Finally how I resolved it :

最后我是如何解决它的:

  • opened the project.pbxproj for the library in a text editor
  • searched for VALID_ARCHS
  • there were 4 occurrences, 2 of which did not contain arm64
  • I manually added arm64 in the chain (VALID_ARCHS = "arm64 i386 armv7 armv7s")
  • rebuild the lib and it was all right
  • 在文本编辑器中打开库的 project.pbxproj
  • 搜索了VALID_ARCHS
  • 出现了 4 次,其中2 次不包含 arm64
  • 我在链中手动添加了 arm64 (VALID_ARCHS = "arm64 i386 armv7 armv7s")
  • 重建库,一切正常

Seems sometimes the build settings displayed by XCode is incomplete, and doesn't correspond precisely to the project file.

似乎有时 XCode 显示的构建设置不完整,并且与项目文件不完全对应。

回答by GeRyCh

You should also check if Deployment Target within Build Settings is the same for dependant and dependency. I noticed that I had iOS 13 being set for a static library target, while iOS 10.0 was defined for a framework that consumes that library. Switchin both to 10.0 resolved the issue.

您还应该检查构建设置中的部署目标对于依赖和依赖是否相同。我注意到我为静态库目标设置了 iOS 13,而为使用该库的框架定义了 iOS 10.0。切换到 10.0 解决了这个问题。

回答by Chandni - Systematix

This issue will not occur when we run the application on device. You can check it by running the code on iOS device.

当我们在设备上运行应用程序时,不会发生此问题。您可以通过在 iOS 设备上运行代码来检查它。

回答by JESERRANO

To me it was fixed setting the Build Active Architecture Onlyto Multiple values, to do that, you have to expand it and set Debugto YESand Releaseto No. And now, it compiles on my device.

对我来说,它是固定设置Build Active Architecture OnlyMultiple values,要做到这一点,你必须把它和一组扩展DebugYESReleaseNo。现在,它可以在我的设备上编译。