Declare global variables, the global function must be declared in the CPP, the other class refers to the global variable to include the CPP h file, and then an extern. Otherwise, the duplicate definition error is prone to occur.
How does this "easy" explain it?
For example, if a global variable is declared in A.h
int Global;
In the B.h
" A.h " ..... extern int Global, ... ..
Then you include A.h equivalent to the declaration of global variables in A.h also included, the compiler will be considered a duplicate definition.
So global variables and function declarations must be in CPP, and when a function is implemented in the. h file, the VS compiler reports this error.
Workaround
1. Add inline before the function declaration in. h
2. Add/force in the additional options, command line, link, properties----
The above is loaded from David_hu.
I also encountered this error, but the whole project contains too many files, bad analysis contains the relationship, but the problem should be similar.
My solution is to:
Item –> Properties –> linker –> command line –> additional options add/force
It solved the error, but there was a bunch of warning.
Fatal error LNK1169: find one or more multi-definition symbols