简体   繁体   中英

C++ MySQL Linker errors

I am new to Visual C++. I wanted to work with MySQL/C++. So, I

  • Installed MySQL on my machine Installed VS 2010 Professional on my machine
  • From the internet, I found that My SQL drivers are found in

C:\\Program Files\\MySQL\\Connector.C++ 1.1\\include <-- Headers

C:\\Program Files\\MySQL\\Connector.C++ 1.1\\lib <-- Libs

  • I made a sample program, which I copied from this .
  • Build the project
  • Got errors related to boost
  • Downloaded Boost from Download boost_1_61_0.7z (74.8 MB)
  • Unzipped the archive
  • Added Include path using Project Properties > C/C++ > General > Additional Include Directories

在此处输入图片说明

  • Added Linker additional libraries using Project Properties > Linker > General > Additional Library Directories

在此处输入图片说明

  • Built the Project
  • Now it fails with below errors

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$_wmain$0

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall sql::SQLException::getErrorCode(void)const " (__imp_?getErrorCode@SQLException@sql@@QBEHXZ) referenced in function __catch$_wmain$0 1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::~SQLString(void)" (__imp_??1SQLString@sql@@QAE@XZ) referenced in function _wmain

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sql::SQLString::SQLString(char const * const)" (__imp_??0SQLString@sql@@QAE@QBD@Z) referenced in function _wmain

1>DemoDB.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _wmain

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLString::asStdString(void)const " (__imp_?asStdString@SQLString@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "class std::basic_ostream > & __cdecl std::operator<<(class std::basic_ostream > &,class sql::SQLString const &)" (??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABVSQLString@sql@@@Z)

在此处输入图片说明

Please help. I am totally stuck

Edit:

This line is causing below error

cout << ", SQLState: " << e.getSQLState() << " )" << endl;

1>DemoDB.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string,class std::allocator > const & __thiscall sql::SQLException::getSQLState(void)const " (__imp_?getSQLState@SQLException@sql@@QBEABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$_wmain$0

I have referred below so far, but no help

I managed to solve this, after a lot of struggle. Below is what helped me

  • First, went to Project Properties > Configuration Manager > "Created new configuration for Platform x64 , as my MySQL library was 64-bit

在此处输入图片说明

  • Second, went to Project Properties > C/C++ > General > Additional Include Directories and included path for MySQL C++ Connector & MySQL Connector C

在此处输入图片说明

  • Third, went to Project Properties > Linker > General > Additional Libraries Directories and added path for MySQL C++ connector

在此处输入图片说明

  • Fourth, went to Project Properties > Linker > Input > Additional Dependencies and added mysqlcppcon.lib

在此处输入图片说明

After all this, built the project and it ran fine ! :)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM