When you recently compiled the Larbin_daemon crawler server-side hypervisor, you will always report the following error:
g++-c-o editconf.o editconf.cppeditconf.cpp:49:8: error:redefinition of ' std::string ProjectG ' editConf.h:34:8: Error : ' std::string PROJECTG ' previously declared hereeditconf.cpp:50:8: Error:redefinition of ' std::string IpG ' editConf.h : 35:8: Error: ' std::string IpG ' previously declared hereeditconf.cpp:51:8: Error:redefinition of ' std::string HttpPortG ' Editconf.h:36:8: Error: ' std::string HTTPPORTG ' previously declared hereeditconf.cpp:52:8: Error:redefinition of ' std:: String PAGESCONNEXIONSG ' Editconf.h:37:8: Error: ' std::string PAGESCONNEXIONSG ' previously declared HereeditConf.cpp : 53:8: Error:redefinition of ' std::string dnsconnexionsg ' editconf.h:38:8: Error: ' std::string dnsconnexionsg ' Previously declared hereeditconf.cpp:54:8: Error:redefinition of ' std::string depthinsiteg ' editConf.h:39:8: Error: ' std::string Depthinsiteg ' previously declared hereeditconf.cpp:55:8: Error:redefinition of ' std::string Waitdurationg ' Editconf.h:40:8: Error: ' std::string waitdurationg ' Previously declared Hereeditconf.cpp:56:8: error:redefinition of ' std::string timeoutpageg ' editConf.h:41:8: Error: ' std:: String Timeoutpageg ' previously declared hereeditconf.cpp:57:8: Error:redefinition of ' std::string TIMEOUTINCRG ' Editconf.h:42:8: Error: ' std::string TIMEOUTINCRG ' previously declared heremake: * * * [EDITCONF.O] Error 1
Very confused, clearly defined only once!
In fact
In EditConf.h, there is the following code snippet:
String projectg;//g represents global, and the class also has a corresponding private variable string ipg;string httpportg;string pagesconnexionsg;string dnsconnexionsg; String depthinsiteg;string waitdurationg;string timeoutpageg;string TIMEOUTINCRG;
It is then used directly in the EditConf.cpp (to assign something) such as:
HTTPPORTG = r[6];
The editConf.h header file is included in both EditConf.cpp and Main.cpp, which is where the problem lies.
When you declare a variable in the header file, As I wrote in editConf.h, each source file that contains the header file, whether direct or indirect, obtains a copy of the variable itself, so when you link all the. o files together, linker will assume that the variable is instantiated in multiple. o files.
The workaround is to instantiate the variable in the header file (such as editConf.h) with extern, and in the corresponding source file (such as EditConf.cpp).
Resources:
Http://stackoverflow.com/questions/18763270/c-linking-error-with-multiple-definition-on-linux
Linux C + + Compiler error: "Multiple definition of"/"does not name a type"