I have searched through all the questions on here trying to find a solution and it just isnt happening.
Error
1>MySQLTest.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main
What I have tried
I know this is a linker error. So I have modified the include and library directory options in VS2010 to point to the MySQL Server libraries and the Connection++ libraries
Libraries:
C:\Programming\boost_1_55_0\stage\lib
C:\Program Files\MySQL\Connector C++ 1.1.3\lib
C:\Program Files\MySQL\MySQL Server 5.6\lib
Includes:
C:\Programming\boost_1_55_0
C:\Program Files\MySQL\Connector C++ 1.1.3\include
C:\Program Files\MySQL\Connector C++ 1.1.3\include\cppconn
I have read in another thread that the get_driver_instance function is only available when dynamically loading the library. It said to define mysqlcppconn_EXPORTS.
get_driver_instance() is now only available in dynamic library builds - static builds do not have this symbol. This was done to accommodate loading the DLL with LoadLibrary or dlopen. If you do not use CMake for building the source code you will need to define mysqlcppconn_EXPORTS if you are loading dynamically and want to use the get_driver_instance() entry point.
I defined this and it still does not work. There is another define (CPPCONN_PUBLIC_FUNC) that people said to use if I wanted to statically link. I tried this too and I still get that error. Preferably I would like to just statically link everything and use a different way of accessing the driver if possible. Is there another way other than get_driver_instance()?
Note: SQLString is working fine. So I am properly linking certain things. I just do not know why this is erring out with this one function.
I have the 64 bit version of the connector installed. Along with mysql Server and workbench.
Here is the code I am trying to run:
#include "stdafx.h"
//#define CPPCONN_PUBLIC_FUNC
/* Standard C++ headers */
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
#include <Windows.h>
/* MySQL Connector/C++ specific headers */
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>
using namespace std;
using namespace sql;
int main(int argc, _TCHAR* argv[])
{
sql::mysql::MySQL_Driver *driver;
Connection *con;
/* initiate url, user, password and database variables */
const sql::SQLString url = "tcp://127.0.0.1:3306";
const sql::SQLString user = "root";
const sql::SQLString password = "admin";
const sql::SQLString database = "store";
driver = sql::mysql::get_mysql_driver_instance();
/* create a database connection using the Driver */
con = driver->connect(url, user, password);
system("PAUSE");
return 0;
}