Visual c++ visualc&x2B+;链接器错误“;已在“OBJ”中定义;及;未解析的外部符号“;(Mysql+;+;) 在Visual C++ 2010环境下,我有一个未来的命令行程序。我使用MySQL++库,它是正确构建和安装的

Visual c++ visualc&x2B+;链接器错误“;已在“OBJ”中定义;及;未解析的外部符号“;(Mysql+;+;) 在Visual C++ 2010环境下,我有一个未来的命令行程序。我使用MySQL++库,它是正确构建和安装的,visual-c++,linker,mysql++,Visual C++,Linker,Mysql++,首先,我在stdafx.h中定义了一些全局文件(程序非常简单,因此我基本上使用该文件满足所有头文件的需要,而不使用任何其他头文件。头文件通常使用“#if!defined”…“#endif”包装。链接器抱怨: Error 2 error LNK2005: "__int64 last_local_time" (?last_local_time@@3_JA) already defined in coreprocessing.obj C:\Tsukasa\ilya\DataImporter\D

首先,我在stdafx.h中定义了一些全局文件(程序非常简单,因此我基本上使用该文件满足所有头文件的需要,而不使用任何其他头文件。头文件通常使用“#if!defined”…“#endif”包装。链接器抱怨:

Error   2   error LNK2005: "__int64 last_local_time" (?last_local_time@@3_JA) already defined in coreprocessing.obj C:\Tsukasa\ilya\DataImporter\DataImporter\stdafx.obj
Error   3   error LNK2005: "bool debug" (?debug@@3_NA) already defined in coreprocessing.obj    C:\Tsukasa\ilya\DataImporter\DataImporter\stdafx.obj
Error   4   error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > user" (?user@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in coreprocessing.obj   C:\Tsukasa\ilya\DataImporter\DataImporter\stdafx.obj
Error   5   error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > server" (?server@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in coreprocessing.obj   C:\Tsukasa\ilya\DataImporter\DataImporter\stdafx.obj
虽然在属性“Library Directories”中包含MySQL++的LIB文件夹路径,但配置为Debug,LIB文件夹中有以下文件:*mysqlpp_d.dll mysqlpp_d.LIB**


如果有人能帮助我了解我的错误,我将不胜感激。

错误9和10是因为我忘记在项目属性>链接器>其他依赖项中添加库mysqlpp.lib/mysqlpp_d.lib


因此,将路径添加到VC目录到Include和Library是不够的。

奇怪,但是将几个预定义的全局变量从.h移动到.cpp文件解决了其余的链接问题。难道.h文件与.cpp文件的代码不一样吗?

可能重复感谢。实际上,看起来非常类似。
Error   9   error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall mysqlpp::Query::`vbase destructor'(void)" (__imp_??_DQuery@mysqlpp@@QAEXXZ) referenced in function "class mysqlpp::Query * __cdecl connectToDb(void)" (?connectToDb@@YAPAVQuery@mysqlpp@@XZ)   C:\Tsukasa\ilya\DataImporter\DataImporter\coreprocessing.obj
Error   10  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mysqlpp::DateTime::operator __int64(void)const " (__imp_??BDateTime@mysqlpp@@QBE_JXZ) referenced in function "class mysqlpp::Query * __cdecl connectToDb(void)" (?connectToDb@@YAPAVQuery@mysqlpp@@XZ)  C:\Tsukasa\ilya\DataImporter\DataImporter\coreprocessing.obj