-->

ios static library Undefined symbols for architect

2019-06-11 17:29发布

问题:

lipo -info libXxxx.a Architectures in the fat file: libXxxx.a are: armv7 i386 arm64

But compiler in the dependant project is giving linking error,

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_ClassXXXX", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Am I missing something? All the lib project's target have Architectures: Standard Architectures (armv7, arm64) and Valid Architectures arm64, armv7, armv7s

in my lipo command while making universal binary I am lipo-ing both from iphonesimulator and iphoneos folder.

回答1:

Your main clue is that it says "symbol(s) not found for architecture x86_64" instead of "symbol(s) not found for architecture i386".

The fix is to tweak your build settings to allow a 32-bit build.

1) Select your project file in the Project Navigator (the left sidebar)

2) Select your project's target (first entry under TARGETS in the panel that just came up)

3) Find the "Architectures" setting (make sure "All" is selected if you can't find "Architectures")

4) Change it from "Standard Architectures" to "Universal" (or explicitly "32-bit" if you prefer)

You should be able to build after doing this.



回答2:

You need to create a universal binary including following architectures in your static library project. The architectures should be including 64-bit, armv7, armv7s, arm64.

Now when you do a lipo -info anyStaticLibrary.a on terminal - you should see armv7 armv7s i386 x86_64 arm64 architectures for your fat binary.

Also note that the project which uses the above static library can work fine with the default settings of the architectures.