SimpleGuy
SimpleGuy

Reputation: 2894

C++ MySQL Linker errors

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

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

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

enter image description here

enter image description here

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)

enter image description here

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

Upvotes: 1

Views: 2608

Answers (1)

SimpleGuy
SimpleGuy

Reputation: 2894

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

Upvotes: 5

Related Questions