0

My problem is when I try to connect to MySQL from C++. I have seen page http://www.mysql.com/ and I have read documentation. I downloaded MySQL client with C/C++ connector. I have Windows 7. My configuration in project in Visual Studio 2013 is:

Properities->C/C++->Additional Include Directories:

C:\Program Files\MySQL\MySQL Server 5.6\include
C:\Program Files\MySQL\MySQL Connector C 6.1.3\include
C:\Program Files\MySQL\Connector C++ 1.1.3\include
C:\Users\Darek\Desktop\Anglia\boost_1_55_0

Properities->Linker->General->Additional Library Directories:

C:\Program Files\MySQL\Connector C++ 1.1.3\lib\opt
C:\Program Files\MySQL\MySQL Connector C 6.1.3\lib
C:\Program Files\MySQL\MySQL Server 5.6\lib

Properities->Linker->Input->Additional Dependencies:

mysqlcppconn-static.lib
libmysql.lib
mysqlcppconn.lib
mysqlclient.lib

Properities->C/C++->Preprocessor->Preprocessor Definition:

WIN32
NDEBUG
_CONSOLE
_LIB
CPPCONN_PUBLIC_FUNC=

Code of my project is:

#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn\driver.h>
#include <cppconn\exception.h>
#include <cppconn\resultset.h>
#include <cppconn\statement.h>
using namespace std;
int main()
{
    sql::mysql::MySQL_Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;
    driver = sql::mysql::get_mysql_driver_instance();  //In this line is error
    //con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
    return 0;
}

When I compile this project I get error:

1>main.obj : error LNK2001: unresolved external symbol "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (?get_driver_instance@mysql@sql@@YAPAVMySQL_Driver@12@XZ)

Do you know how to solve this error? Please help. Thanks for help.

John Bupit
  • 10,406
  • 8
  • 39
  • 75
  • is your target platform 32 or 64 bit? – YePhIcK Jul 01 '14 at 19:11
  • The answer can be found by searching the web for "mysql get_driver_instance". That's what I did. – Thomas Matthews Jul 01 '14 at 19:35
  • See my post: http://stackoverflow.com/questions/7127284/unresolved-symbol-sqlmysqlget-driver-instancevoid – Thomas Matthews Jul 01 '14 at 19:50
  • My platform is 64 bit. Windows 7 64 bit. – user3794975 Jul 01 '14 at 21:36
  • Thanks Thomas Matthews for your comment. But I was searching in the web for "mysql get_driver_instance" and another else too but I didn`t find solution of my problem. I found similar problems ,I made steps from them but problem still exists. Maybe I wasn`t searching enough good but... Please for help. – user3794975 Jul 01 '14 at 22:00
  • Target platform is what you build for (not the Windows you are running on). Could you check the project properties to see if your target is 32 or 64 bit? – YePhIcK Jul 02 '14 at 19:48

1 Answers1

0

I'm not using mysqlclient.lib.

Here are my Preprocessor Definitions:

WIN32
WINVER=0x0400
__WXMSW__
_WINDOWS
wxUSE_GUI1
_DEBUG
__WXDEBUG__
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
CPPCONN_PUBLIC_FUNC=
HAVE_INT8_T=1
mysqlcppconn_EXPORTS

I'm also using UNICODE setting.

You may have to download the connector source and rebuild it with your settings.

Per my comment above, search the web for "mysql get_driver_instance" and you should be above to confirm my settings above.

I'm using Visual Studio 2010 Professional on Windows 7 and Visual Studio 2008 on Windows Vista. The settings work on both platforms.

Edit 1:
If you search StackOverflow for "mysql Thomas Matthews" you'll find my postings very similar to yours.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
  • Thanks Thomas for your reply. I threw out mysqlclient.lib from Additional Dependencies and changed Preprocessor Definitions on your Definitions but I have still the same error. You said "download connector source", where can I download it? do you mean to install connector c++ from source? From www.mysql.com page? Or another? – user3794975 Jul 01 '14 at 22:05
  • I don't understand people. I typed "mysql connector c++" into the web search engine (Google) and the first item is "MySql Connector C++ download". What is the next step? I clicked on it to get to the download page. Go to the bottom, in the drop down box for platforms, choose "Source Code". – Thomas Matthews Jul 02 '14 at 14:24