First, error hints
We may often encounter such an error during our code writing:
1. Duplicate symbols for architecture x86_64
2.clang: error:linker command failed with exit code 1 (use-v to see invocation)
Second, analysis of the cause of the error
Read the cause of the error carefully to find a few key words: "Duplicate" and "symbols".
The Chinese meaning of duplicate is "duplicated and duplicated", while symbols means "symbol". That is, it is possible to introduce repetitive things into your project.
Iii. Solutions to problems
I summed up, there are three kinds of duplicate errors:
3.1 Duplicate import of the same file
The first scenario is that you re-import a class or file in your project, which generally occurs when you add a third-party library, and you import the same class again without knowing it.
In the project I created a src folder, the person class has been copied again and added to the project,
At this point, the following error occurred after COMMAND + B was compiled:
Can be seen to report or duplicate error, although duplicate front of the number may not be accurate, but as long as you see duplicate this keyword can go to your project to find whether there is duplicate things are imported.
3.2 #import "XXX.h" was written #import "XXX.M"
The second case: the project in the #import introduction of the header file, the #import "XXX.h" written #import "XXX.M". Incorrect introduction of. m header file
I have a class of person in my project, and then I want to initialize an object in the main function, this time I need to introduce the. h file of the person class first. This time I introduced the. m file,
Command + B Compiles after errors are found,
You will find that the duplicate is still a mistake.
3.3 Repeatedly defining something in multiple files
This is provided by netizens, the reason for the error is as follows: The same enumeration was defined in two files, resulting in deplicate errors.
iOS development duplicate symbols for architecture x86_64 error