Duplicate symbols for architecture x86_64 error in iOS development

【main content:】

 

1. Error message

2.  Analyze the cause of the error

3. Solutions to problems

 

 

 

1. Error message

 

In the process of writing code, we may often encounter such an error:

 

[objc]  view plain copy  
 
  1. <span style="font-size:32px;color:#ff0000;">ld: 4 duplicate symbols for architecture x86_64  
  2. clang: error: linker command failed with exit code 1 (use -v to see invocation)</span>  

 

As shown in the figure:

 

 

 

Second, analyze the cause of the error

A careful reading of the reason for the error reveals several key words: "duplicate" and "symbols".

The Chinese meaning of duplicate is "repeated, duplicated", while symbols means "symbol". That is, it may introduce duplicate things in your project.

 

 

 

Third, the solution to the problem

 

I summed it up, there are generally three situations in which this error occurs when duplicate occurs:

 

3.1 Import the same file repeatedly

   The first case: a certain class or file is imported repeatedly in the project, which generally occurs when you add a third-party library, and the same class is imported again without knowing it.

   In the figure below, I created a new src folder in the project, copied the Person class again and again and added it to the project, as shown in the figure:

 

At this time, the following error occurs after command + B compiles:

 

 It can be seen that the report is still a duplicate error. Although the number in front of the duplicate may not be accurate, as long as you see the duplicate keyword, you can go to your project to find out whether there are duplicate things imported.

 

 

3.2 #import "XXX.h" is written as #import "XXX.m"

  The second case: When #import introduces the header file in the project, #import "XXX.h" is written as #import "XXX.m". Incorrect introduction of .m header file 

There is a Person class in my project, and then I want to initialize an object in the main function. At this time, I need to introduce the .h file of the Person class first. At this time, I introduced the .m file, as shown in the figure:

    Command + B found an error after compiling, as shown in the figure:

You will find that the error is still duplicate.

 

 

 

3.3 Defining something repeatedly in multiple files

 

This is provided by netizens. The reason for the error is as follows: The same enumeration is defined in two files, resulting in a duplicate error.

 

At present, I only found that these three operations will bring this problem. If other operations will bring this problem, you are welcome to bring it up and help me continue to improve my blog.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325816834&siteId=291194637