iOS Static Library Xcode (linking errors)

2019-08-09 23:09发布

问题:

I created a static library with Xcode I have compiled selecting a device.

I added this to my library test project in Xcode 4.6

but I always have 2 errors during the linking...

I followed this tutorial: Static Library iOS Tutorial

if I download the sample code I have the same errors:

ld: warning: ignoring file /Users/Downloads/ICodeBlogStaticLibrarySample/MathTest/Classes/iCodeBlogsMathLibrary/libICodeMathUtils.a, missing required architecture i386 in file /Users/Downloads/ICodeBlogStaticLibrarySample/MathTest/Classes/iCodeBlogsMathLibrary/libICodeMathUtils.a (2 slices) Undefined symbols for architecture i386: "_OBJC_CLASS_$_MathFunctions", referenced from: objc-class-ref in MathTestAppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

回答1:

I had once made a static lirary , I had the same problem . Solution was to "Run the app on device " not on simulator , it works fine then !!! Hope this helps...



回答2:

I followed this step by step tutorial:

Tutorial

in particular I had to add these flags: -ObjC and -all_load



回答3:

You must have selected iOS simulator while building the project. Select iOS device and it should be fine.



回答4:

Do read and try to understand the error message, it's a meaningful English phrase.

symbol(s) not found for architecture i386

So there's no compiled code for the i386 architecture in the library. This means that either it's compiled for ARM only (for actual iOS devices, like iPhone or iPad), or for the 64-bit simulator (x86_64). Use otool to find out the architectures present in the library.