0

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;
}

2 Answers 2

1

There ended up being a slight error in one of my assumptions. I assumed visual studio defaulted its build based on the system you are running. It was building a 32 bit version of the application(on a 64 bit machine), and I am using 64 bit libraries. If you do this the linker will not look at libraries compiled using a 64 bit target.

The machine type has to be changed to 64 bit in the following area to get my build to work properly:

Project -> "project_name" Properties -> Linker -> Advanced -> Target Machine set to 'x64'

There may also be another attribute that had to be changed that is related (making sure its building for 64 bit) but I cannot remember where it was. I remember it being very obvious to find though.

Sign up to request clarification or add additional context in comments.

Comments

1

I solved this problem by downloading a C++ connector from MySQL website and a libmysql.dll 32bit from dllfiles.com

Note: MySQL Installer is 32 bit, but will install both 32 bit and 64 bit binaries depend on the platform of your computer. I'm using Win8 64bit and VS2010 32bit, my target platform is 32bit. But the connector provided with MySQL is 64bit, so it will cause unresolved symbol problem.

So you have to download an independent 32bit connector and use the lib in it. Also, you must download libmySQL.dll 32bit

1 Comment

Looking back at some old questions. This deserved an upvote considering you mention the incompatibility between the 64 and 32 bit binaries.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.