ChatGPT解决这个技术问题 Extra ChatGPT

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

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;

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)

I tried adding i386 in the Architectures. but no luck


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

Before:

https://i.stack.imgur.com/YnqsV.png

After:

https://i.stack.imgur.com/p2lnm.png

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.

Hope this helps.


This solved it for me. There are many ways to build for an architecture you're not intending and future searchers might want to look through many of these answers to see if you come upon the one that applies to you!
Update: After xcode 5 and iPhone 64-bit simulator, i have an error with libPods.a being built for another architecture, but it doesn't happen in other types of simulators :\
@Nour1991 try setting Build Settings -> Build Active Architecture Only to No
@MMiroslav i had to put it to yes, because I need to deploy in debug.
C
Community

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 this link > Clean and Build again.


For Deleting Derived Data in XCode 8, see here: stackoverflow.com/questions/38016143/…
a
achow

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

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

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


k
kiranpradeep

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

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 = ios simulator or 32 bit build on mac os x

armv6 armv7 arm7s = ios device

x86_64 = 64 bit build on 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 -info will print a combination of above architectures.


Although, this didn't answer the OP. This is a great tool for debugging this issue. What I'd like to know is, how do you build a binary with all the above mentioned architectures?
Nevermind, I found the answer here: stackoverflow.com/questions/2793392/… which uses lipo to combine builds using the '-create' flag
ld: warning: building for iOS-armv7 but attempting to link with file built for iOS-arm64 Undefined symbols for architecture armv7 this warning leads to clang: error: linker command failed with exit code 1 (use -v to see invocation) this error. If you are using own library/framework then change this in both the project Library as well as Adopter. Build Settings -> Build Active Architecture Only to No
A
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).

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

Do not judge me if I am captain obvious :)


In addition to Alexander's advice, I would advise that you make sure the 'Build Active Architecture Only' setting is set to 'NO'. This tripped me up recently.
C
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.


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


Checked all the other suggestions on this question, this was the one that tripped me up
E
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.

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

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


J
JESERRANO

To me it was fixed setting the Build Active Architecture Only to Multiple values, to do that, you have to expand it and set Debug to YES and Release to No. And now, it compiles on my device.


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


f
flyers

I had an architecture of armv7s as well. I deleted it and made sure the armv6 and armv7 were the only two listed. It works now


You shouldn't exclude armv7s

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now