File Was Built for Archive Which Is Not the Architecture Being Linked (I386)

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

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:

iOS Device Settings

After:

iPhone 5.1 Simulator Settings

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.

Xcode error: file was built for archive which is not the architecture being linked (x86_64)

The easiest solution is probably just build the static archive with intel slices (against the iOS Simulator SDK) in addition to the arm ones such that it is 4-way fat (i386+x86_64/iOS Simualtor and armv7/arm64/iOS).

If that is not possible, please explain why that is not possible for you and file a radar at http://bugreport.apple.com, so we can address whatever problem is preventing you from building your static archive.

If you want to proceed without using the static archive in the iOS Simulator build, you will need to avoid using the XYXClass in the simulator. You can do this by doing something like:

#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR
// Do sim-specific fallbacks
#else
// Do stuff with XYXClass
#endif

Note that the "warning: ignoring file libXYZ.a ..." message is not fatal. It's just a warning that you can ignore. The fatal part is your use of the XYXClass which doesn't have an implementation in x86_64.

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

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.

Static library built for archive which is not the architecture being linked (x86_64)

Thanks to this question with the same problem, I could look into this problem. I don't have much experience with static libraries, but I'll try to explain the problem.

For some reason, Mac OSX ar utility creates "subdirectories" in the static library. For example, building the sba library, the steps of make to build the static library from the object file is:

ar crv libsba.v1.5.a sba_levmar.o sba_levmar_wrap.o sba_lapack.o sba_crsm.o sba_chkjac.o

After that, if I look at the contents of the static library, I saw that in addition to the files, there are some strange directorios:

$ ar -t libsba.v1.5.a 
__.SYMDEF
/
//
sba_levmar.o/
/0
sba_lapack.o/
sba_crsm.o/
sba_chkjac.o/
sba_levmar.o
sba_levmar_wrap.o
sba_lapack.o
sba_crsm.o
sba_chkjac.o
sba_levmar.o
sba_levmar_wrap.o
sba_lapack.o
sba_crsm.o
sba_chkjac.o

If we try to extract those files, we get some errors regarding the subdirectories:

$ ar -x libsba.v1.5.a 
ar: /: Is a directory
ar: //: Is a directory
ar: sba_levmar.o/: Not a directory
ar: /0: Permission denied
ar: sba_lapack.o/: Not a directory
ar: sba_crsm.o/: Not a directory
ar: sba_chkjac.o/: Not a directory

Now, if we create the lib again with the extracted object files, it will work:

$ ar crv libsba.v1.5.a lib_o/*.o
a - lib_o/sba_chkjac.o
a - lib_o/sba_crsm.o
a - lib_o/sba_lapack.o
a - lib_o/sba_levmar.o
a - lib_o/sba_levmar_wrap.o

$ ar -t libsba.v1.5.a
__.SYMDEF SORTED
sba_chkjac.o
sba_crsm.o
sba_lapack.o
sba_levmar.o
sba_levmar_wrap.o

I don't understand the reason at all, but it worked for me.

Xcode 6.1: file was built for x86_64 which is not the architecture being linked (i386)

Make sure you have i386 and x86_64 listed in your Architectures in Build settings for your lib. Also set Build Active Architecture Only explicitly to No.

Why does the linker complain “file was built for archive which is not the architecture being linked” when the architecture is correct?

The error message is in fact misleading: The issue isn’t a mismatch in architecture, it’s the fact static libraries (.a files) cannot be nested:

⟩⟩⟩ nm bar.a

bar.a(bar.o):
0000000000000000 T _bar

(Note that the entry _foo from foo.a is missing!)

But since ar is originally a general-purpose archival utility, it has no qualms creating a nested archive via

ar rcs bar.a foo.a bar.o

As we can verify by listing its contents:

⟩⟩⟩ ar t bar.a
__.SYMDEF SORTED
foo.a
bar.o

To fix the problem, don’t nest archives but rather pack the object files directly:

rm bar.a
ar rcs bar.a foo.o bar.o
clang -o test bar.a test.o

OSX : File was built for archive which is not the architecture being linked (i386)

For the GlutRenderer.o, SceneDescription.o, RayTraceData.o files: add them to your clean section and make clean. For now you are cleaning only one file: tracecone.o. Perhaps other object files were built before you added -m32 flag to your makefile. You can also remove all object files manually.

Run find . | grep '\.o$' in source root directory to check if there is any object file left after the cleaning.


For the libraygraph.a and libvrmath.a: those libs must be built with -m32 flag too.



Related Topics



Leave a reply



Submit