The solution to multiple definition of is summarized as follows:
Cause:
When multiple files contain the same header file, and your. h file does not contain Conditional compilation
# Ifndef test_h
# Define test_h
# Endif
Each file is generated to generate an independent identifier. When the compiler is connected, all the symbols in the project are integrated. Because there are duplicate variables in the file, a duplicate definition error occurs.
Method 1:
It is a habit to add Conditional compilation to each header file to avoid multiple interpretations when the file is referenced multiple times. This method will solve most of the low-level problems.
Method 2:
When method 1 is invalid, all global variables can be put into a header file global. in H (the name is random, but Conditional compilation is required), each variable is prefixed with extern and declared that these variables will be defined in other files. Create a. C or. cpp file corresponding to the header file name, such as global. C. Declare all global variables in it. Example: void (* handl_display )();
Then, let the file that involves global variables include "Global. H". In this way, a global. O will be generated for global. c compilation, and then delivered to the. otrace of other files into executable files.
Method 3:
The lazy method adds static before all global variables to declare static variables. It can also solve the problem.
All methods come from the Internet, O (∩ _ ∩) O Haha ~
Thanks to all the guys who provide the methods ~
ArticleSource: http://general.blog.51cto.com/927298/235077