Visual C++ linker errors “already defined in OBJ” and “unresolved external symbol” (Mysql++)

StackOverflow https://stackoverflow.com/questions/11922419

  •  25-06-2021
  •  | 
  •  

I have a future command-line program in Visual C++ 2010 environment. I employ MySQL++ library, that is built and installed properly.

First, I have some globals defined in stdafx.h (program is very simplistic so I basically used the file for all my header needs, and do not use any other header file. The header file has usual "#if !defined "... "#endif" wrapping. Linker complains:

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

other linker errors are related to Mysql++ library.

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

while in Properties "Library Directories" includes the path of LIB folder for MySQL++, configuration is Debug and I have the following files in the LIB folder: **mysqlpp_d.dll mysqlpp_d.lib **.

I appreciate if someone can help with the insights of what I did wrong.

有帮助吗?

解决方案

The errors 9 and 10 were because I forgot to add library mysqlpp.lib/mysqlpp_d.lib in Project properties > Linker > Additional Dependencies.

So, adding pathes to VC directories to Includes and Libraries was not enough.

其他提示

Strange, but moving several pre-defined global variables from .h to .cpp file resolved rest of linking problems. Aren't .h files just the same code as .cpp files?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top