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?
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!
解决方案
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.