Simply put, Undefined symbols is basically equivalent to Java classnotfoundexception, the most common reasons for this are:
Build without the framework
For example, there's a piece of code I used OpenGL to introduce a header file
#import <OpenGLES/ES2/glext.h>
Build, compile stage no problem, but link error undefined symbols for architecture xxx (here XXX may be armv7s,armv7 or arm64, depending on the configuration, will say later). The workaround is to add the opengles.framework to the build phases link Binary with libraries, and then compile on the OK
Project-dependent libraries, compile-time architectures mismatch
In build settings, the first architectures, which is the compilation architecture of the configuration project, consists of the following 3 configuration items:
Architectures: The arch that will be created by the bundle support
Valid architectures: Effective arch, this configuration is useless, generally configured as armv7,armv7s,arm64.
Build Active Architecture only: whether to hit only the arch of the current connected device
On the real machine, there are 3 common arch: armv7,armv7s,arm64
ARMV7: Corresponds to IPhone4 and iphone4s
armv7s: corresponding to IPhone5 and IPHONE5C, and the early ipad
ARM64/ARMV8: Corresponds to IPhone5S and IPhone6 series, and compare new ipad, such as ipad Mini2,ipad Air
Arch is backwards compatible, such as a armv7-out package that can be run on a arm64 architecture device; So if the app is going to support the IPhone4 series, architectures must include ARMV7.
The build Active Architecture only refers to whether the schema of only the currently connected devices is packaged. For example, architectures configuration armv7 and Arm64,build Active Architecture only set to Yes, then when the connection IPhone4, will be armv7 packaging; when connecting iphone5s, will be packaged in arm64. If build Active Architecture only is set to No, then all 2 architectures will be hit and executed at runtime based on the actual device architecture. So the final bundle will be larger than the volume
Having said so much, why does this cause undefined symbols? Because there is another rule, the build link stage, the. o file generated with arm64, cannot link the. o file generated with armv7s or ARMV7, so it will link error
The common scenario is that the project refers to a third-party library (such as a library from the pod), and this third-party library is packaged with only armv7s and ARMV7, and the project is packaged using arm64, and this time the error undefined symbols due to the inability to link
The solution is to either repackage third-party libraries, add arm64, or remove arm64 from your own project
Sometimes it is impossible to build on the simulator, on the real machine can
I've only met this situation once. Our app can connect an external manufacturer's Bluetooth printer, and the other side provides a lib. When our project introduced this LIB, it will not be able to build on the simulator, but on the real machine is not a problem
iOS build, Undefined symbols for architecture XXX issues Summary