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
int Global;
In B.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.
Solution:
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.
Read More:
- [Solved] error LNK2005: ___pInvalidArgHandler Already defined in libcmtd.lib(invarg.obj)
- [Solved] FATAL CONFIG FILE ERROR: Bad directive or wrong number of arguments
- [Solved] fatal error: openssl/hmac.h: No such file or directory
- [Solved] fatal error: linux/videodev.h: No such file or directory
- [Solved] Fatal error: GLOG/logging. H: there is no such file or directory
- [Solved] ffmpeg Error: fatal error: zlib.h: Not having that file or directory
- [Solved] Denseflow Install Error: fatal error: opencv2/cudaarithm.hpp: No such file or directory
- [Solved] fatal error: jemalloc/jemalloc.h: No such file or directory
- Fatal error: sys/cdefs.h: No such file or directory
- [Solved] fatal: not a git repository (or any of the parent directories): .git
- [Solved] error adding symbols: DSO missing from command line
- No devices detected Fatal server error no screens found
- Ubuntu install and compile OpenCV3.4.0 fatal error: dynlink_nvcuvid.h: No such file or directory #include <dynlink_nv
- [Solved] GCC Compile Error: fatal error: sys/cdefs.h: No such file or directory
- [Solved] pxp_lib.h:19:10: fatal error: linux/pxp_device.h: No such file or directory
- [Solved] xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory #include <expat.h>
- Ionic Save to Gallery Plugin IOS Error: Method ‘requestAuthorization:’ not defined in Plugin ‘PhotoLibrary’ ERROR: Method ‘xxx’ not defined
- Kylin arm64 linux configure: error: cannot guess build type; you must specify one
- Linux accesses the shared directory of windows, pysmb (parameter remote)_Name (defined)
- Clang Error: error: cannot specify -o when generating multiple output files