"Main content:"
1. Error Tips
2. Analyze the cause of the error
3. Problem-Solving approach
First, error tips
This error may be encountered frequently in the process of writing code:
<span style= "Font-size:32px;color: #ff0000;" >ld:4 duplicate symbols for architecture x86_64 clang:error:linker
command failed with exit code 1 (use-v to SE e invocation) </span>
As shown in figure:
Ii. Analysis of the causes of errors
Read the error carefully to find a few key words: "Duplicate" and "symbols".
The Chinese meaning of duplicate is "duplicate, copy", and symbols means "symbol". It is possible to introduce repetitive things into your project.
Iii. problem-solving approach
I sum up, there are generally three kinds of duplicate out of this error:
3.1 Duplicate import of same file
The first scenario: repeatedly importing a class or file in the project, which usually occurs when you add a Third-party library, and then imports the same class without knowing it.
In the image below, I created a src folder in the project, copied the person class again and added it to the project, as shown:
The following error occurred following command + B compilation at this time:
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 duplication of things are imported.
3.2 #import "XXX.h" written #import "xxx.m".
The second case: the project in the #import when the 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, which needs to introduce the. h file of the person class first. This time I introduced the. m file, as shown in figure:
An error was found after COMMAND + B compilation, as shown in figure:
You will find it duplicate this mistake.
3.3 repeatedly defining something in multiple files
This is provided by the Netizen, the reason for the error is as follows: The same enumeration was defined in two files, resulting in deplicate errors.
At present, I only found that these three kinds of operation will bring this problem, other if it will bring this problem, welcome to put forward to help me constantly improve the blog.