1
votes

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

enter image description here

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

enter image description here

  • 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)

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

1
Perhaps the MySQL drivers you installed were from a different version of Visual Studio.drescherjm
@drescherjm I downloaded MySQL from this link (v5.7.14). How can I know the compatibility for MySQL for Visual Studio ? Link --> cdn.mysql.com//Downloads/MySQLInstaller/…SimpleGuy
Does the MySQL library that your are using have automatic linking using a pragma?drescherjm
@drescherjm I believe it has because even though i am not using #pragma my lib is being linked. I solved this defining preprocessor macro "CPPCONN_PUBLIC_FUNC="SimpleGuy
If this is solved you should post your solution as an answer.drescherjm

1 Answers

5
votes

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