XCode/iOS common compilation errors, link errors

Wedge

As the saying goes, there must be reasons for the use of, I write this article is also derived from these two days encountered a specific problem. The company’s products demand in the new version of the APP, a rich text on the mobile phone number can click on add in response to the incident, because unlike Android TextView AutoLink iOS native control attributes have this attribute, I naturally think of the famous open source library YYKit. Thus, after the introduction of Cocoapods to compile, but reported the error

YYKit Static declaration of compiler error’CGRectGetCenter’follows non-static declaration static inline CGPoint CGRectGetCenter (CGRect rect) {
return CGPointMake (CGRectGetMidX (rect), CGRectGetMidY
(rect));}

Thus, all kinds of Baidu, Google, after all, the world is big, we now encounter problems, in general, others have encountered. After that, there are many such errors, but found no such errors associated with YYKit.

The results showed that 2
1 problem: the problem and static function statement (behind the non static statement followed the static declaration)
2 YYKit code itself is no problem, the problem in the project code on the other

Seemingly the same function name with 2 different declarations, global search CGRectGetCenter, and indeed in another category found the same name of the non static function declaration, modify the problem to solve.

Dried food

We used C/C++/Objective-C to compile language, generally applied to the pretreatment, compile, compile, link 4 runtime before, here is the compile and link often possible causes of errors, this paper will continue to update, we hope to help, the reference to some god article, said again thank you!

Linker command failed with exit code 1 error summary

1, the newly added file is the same name as the previous file
There has been a class name, 2 error messages, to the original #import files to see what the third party library, the library one by one comment out, find the library error, then in accordance with the official steps to add it again
3, SVN or Git ignore some files, such as.O and other documents can not update down, check the.O file may be red, you can re add or modify SVN (GIT) ignore settings
4. Delete the.A file and drag it back into the project to solve the problem
5, repeatedly added the file (not checked Copy items if neded this option), it is recommended to delete, add again
6, the project name repeated, there will be the same mistake
7, “Build Settings” -> “Enable Bitcode” is set to “NO” because some SDK does not support Bitcode
8, the reference may be written “#import” “XXXXX.m”, if it is changed to #import “XXXXX.h””
9, the SDK can only be run on a real machine, the simulator will be in error!
10, the parent class created by the custom in a class has no implementation section, and the inherited subclass on this basis is reporting such an error
11, in different parts of the same named static variables, but the real machine debugging error, when running wrong

Example

More than 1. developers, you completed synchronization, found the following error
Undefined symbols for architecture armv7: "_OBJC_CLASS_$_MyPageLogViewController" referenced from: objc-class-ref in BaiduMobStatAppDelegate.o ld: symbol (s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

The class “MyPageLogViewController” appears in the error. You can find the.M file for this class and check his Target Membeship, as shown below

XCode/iOS common compilation errors, link errors

If not checked, click “tick”. Then compile the view.

2., if the new third party library is added, it is not a static library

Find Build settings-> Linking-> Other, Linker, Flags,

XCode/iOS common compilation errors, link errors

modifies this property to -all_load or -ObjC, depending on the case. In short, you can try several times.

3. if you add a third party static library (.A file)
Undefined symbols for architecture armv7: "_OBJC_CLASS_$_BaiduMobStat" referenced from: objc-class-ref in BaiduMobStatAppDelegate.o objc-class-ref in MyPageLogViewController.o (maybe you meant: _OBJC_CLASS_$_BaiduMobStatAppDelegate) ld: symbol (s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

In the use of the library all files there are mistakes, as BaiduMobStatAppDelegate and MyPageLogViewController
this situation is likely to link the static error
road size confusion solution: Build settings-> Search Path-> Library Search Paths to add the corresponding path static library

XCode/iOS common compilation errors, link errors