Declare the global variable. The global function must be declared in CPP. If other classes refer to the global variable, include the H file of the CPP, and then extern. Otherwise, the repeated definition error is likely to occur.
How does this “easy” explain?
For example, if a global variable is declared in A.H
include "A.h" ..... extern int Global; ......
If you include A.H, it is equivalent to including the declaration of global variables in A.H, and the compiler will consider it a duplicate definition.
Therefore, global variables and function declarations must be in CPP when The vs compiler reports this error when there is a function implementation in the H file.
1 Yes Add inline
2 before the function declaration in H In project – > Attribute – > Linker – > Command line – > Add/force to additional options
The above is loaded from David_H
I also encountered this error, but the whole project contains too many files to analyze the inclusion relationship, but the problem should be similar.
my solution is:
Project – > Properties – > Linker – > Command line – > Add /force
to additional options
It solved the error, but there were a lot of warnings.
- cstdio [Error] ‘::fpos_t‘ has not been declared [How to Solve]
- Parse error in ubantu/Linux system [How to Solve]
- Debian9 g++ Compile Error: error: ‘EDOM’ was not declared in this scope
- [Solved] error: ‘QStringLiteral’ was not declared in this scope
- [Solved] Centos error: collect2: fatal error: cannot find ‘ld‘
- [Solved] error: this statement may fall through [-Werror=implicit-fallthrough=]
- MAC: Clion configure C compiler Error: The C compiler identification is unknown
- [Solved] source /etc/profile Error: not a valid identifier
- Linux Error: CMake Error in CMakeLists.txt: No CMAKE_CXX_COMPILER could be found.
- Error: loading shared libraries: cannot open shared object file: No such file or directory
- Windows command execution bypass
- [Solved] Linux C++ warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings]
- Git Clone RPC failed；curl 18 transfer closed with outstanding read data remaining
- [Solved] catkin_make Error: pkg_resources.DistributionNotFound: pyparsing
- [Solved] WSL error: wslregisterdistribution failed with error: 0x800701bc
- Shell Script syntax error near unexpected token `done’
- Ubuntu18.04 Compile A40i SDK Error: misc/create_inode.c:395:18: error: conflicting types for ‘copy_file_range‘
- Ubuntu Server: How to Install Chrome
- Linux useradd Error: Creating mailbox file: File exists
- [Linux] undefined reference to `itoa’