views:

1120

answers:

3

PROBLEM:

Ok, I've been TRYING to follow the sample code on the MySQL Forge Wiki and some other websites that offer a tutorial on how to get a simple database connection, but for some reason, my project always fails at a linking error and I can't figure out why or how to fix it myself (I'm still learning). PLEASE HELP ME! I've included the path directory needed for the header files in the project properties AND provided the path directory to the lib files that are used in the MySQL Connector/C++. The code I'm using is below if someone could give me a helpful hint/ comment on how to fix it. I think it has something to do with connecting to the lib files (because of the linking error) but I don't know of a solution to fix it. Has anyone else had trouble like this?

http://forge.mysql.com/wiki/Connector_C++ http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html#createdb

CODE:

int main() {
    // do something
    sql::mysql::MySQL_Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;
    sql::PreparedStatement *pstmt;

    cout << "Starting Driver Instance" << endl;
    driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();

    return 0;
}

ERROR OUTPUT:

1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\josh bradley\documents\visual studio 2008\projects\test\test\main.cpp(28) : error C2039: 'get_mysql_driver_instance' : is not a member of 'sql::mysql::MySQL_Driver'
1>        c:\program files\mysql\mysql connector c++ 1.0.5\include\mysql_driver.h(25) : see declaration of 'sql::mysql::MySQL_Driver'
1>c:\users\josh bradley\documents\visual studio 2008\projects\test\test\main.cpp(28) : error C3861: 'get_mysql_driver_instance': identifier not found
1>Build log was saved at "file://c:\Users\Josh Bradley\Documents\Visual Studio 2008\Projects\test\test\Debug\BuildLog.htm"
1>test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

UPDATE:

I just wanted to let everybody know that I finally found out how to fix my problem. For anyone having a similar problem, go to http://blog.ulf-wendel.de/?p=215#hello and read through the instructions on how to connect to the mysqlcppconn.lib dynamically. My problem was setting up the actual environment so it would connect to the library correctly and this tutorial helped tremendously!

A: 

The error is a compiler error. It's complaining that it can't find get_mysql_driver_instance() in the specified namespace.

Try double clicking the line:

1>        c:\program files\mysql\mysql connector c++ 1.0.5\include\mysql_driver.h(25) : see declaration of 'sql::mysql::MySQL_Driver'

It will show you the header file, and you can search in there to make sure the function is present.

Soo Wei Tan
A: 

A quick google search suggests that your line should read:

driver = sql::mysql::get_mysql_driver_instance();
andreas buykx
Well, I've already tried that and I get the following linking error still1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_mysql_driver_instance(void)" (__imp_?get_mysql_driver_instance@mysql@sql@@YAPAVMySQL_Driver@12@XZ) referenced in function _main
Josh Bradley
The linking error indicates that you apparently didn't link against the proper library.
andreas buykx
+1  A: 

You must first change your code:

driver = sql::mysql::get_mysql_driver_instance();

And next, you have to link your code with mysqlclient.lib Add the right path of your lib mysqlclient.lib on your project:

Properties->Linker->General-> Additionnal Libraries

Here add the path of your lib.

Nadir SOUALEM