问题
Today I added a class which manages the connection to a MySQL Server. It will be multi-threaded, so I want to use mysql++. I downloaded the newest version and compiled it in debug mode without any errors. Once I added the compiled mysqlpp_d.lib
to my solutions, and of course the other requirements too (mysql 5.0 include and lib), I got some linker errors.
Error 17 error LNK1169: one or more multiply defined symbols found C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxxx\binaries\xxxx.exe 1 1 xxxxx
Error 16 error LNK2005: "public: __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >(int)" (??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z) already defined in xxxxxx.obj C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxxx\trunk\vc10\xxxxx\mysqlpp_d.lib(mysqlpp_d.dll) xxxxxxx
Error 15 error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::str(void)const " (?str@?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in client_context.obj C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxx\trunk\vc10\xxx\mysqlpp_d.lib(mysqlpp_d.dll) xxxxx
Error 14 error LNK2005: "public: void __thiscall std::basic_ostringstream<char,struct std::char_traits<char>,class std::allocator<char> >::`vbase destructor'(void)" (??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ) already defined in xxxxx.obj C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxx\trunk\vc10\xxxx\mysqlpp_d.lib(mysqlpp_d.dll) xxx
Is there a solution for these errors?
BTW: I compiled the whole mysql++ libary without changing any compile configurations.
回答1:
Define MYSQLPP_NO_DLL in Project Properties->C/C++/Preprocessor
回答2:
Try setting /NODEFAULTLIB parameter in project options -> Linker/Input
来源:https://stackoverflow.com/questions/6486447/multiple-problems-linking-mysqlpp-d-lib