|
-
July 13th, 2010, 05:09 PM
#1
Unable to connect MySQL database. Weird _imp_ problem
Hey guys.
I've tried for the past few hours connecting to my MySQL database using C++, but it keeps failing and I dont know why, and I'm really starting to get frustrated with this stuff.
Hope you can help.
Well, as I said, I'm trying to fetch some data from a table inside my MySQL database, using C++ code. So, firstly, I just tried setting it up and create a connection, so this is what I did :
1.Installed the connector
2. Created a new project
3. Configured it as Active(Release)
4. In properties, under C/C++ -> General -> Additional Include Directories, I've added the connector's "include" folder
5. In Linker -> General -> Additional Libary Directories, I've added the "lib/opt" subfolder.
6. I've also added "mysqlcppconn.lib" under Linker -> Input -> Additional Dependencies
After all of this, I tried running this simple code:
---------------------------------------------------
#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(void)
{ sql: river *driver;
sql::Connection *con;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
}
----------------------------------------------------
But I just keeping getting this error:
1>NEW_C++_mySQL.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main
So, I've tried changing the "driver=get_driver_instance();" into
------------------------------------------------
driver = sql::mysql::MySQL_Driver::Instance();
------------------------------------------------
But then I get this error :
1>NEW_C++_mySQL.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sql::mysql::MySQL_Driver * __cdecl sql::mysql::MySQL_Driver::Instance(void)" (__imp_?Instance@MySQL_Driver@mysql@sql@@SAPAV123@XZ) referenced in function _main
I just can't figure out what's wrong with the instancing function, since I believe I linked everything fine.
Any help would be very appreciated, since I need to finish this small project in a very small period of time.
Thanks again
-
July 13th, 2010, 06:43 PM
#2
Re: Unable to connect MySQL database. Weird _imp_ problem
 Originally Posted by skippergeffen
But I just keeping getting this error:
1>NEW_C++_mySQL.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main
You should first identify where this get_driver_instance() function is implemented before you start changing things all over the place.
Once you know where that function resides, then you figure out what needs to be done to have the linker find this function.
Regards,
Paul McKenzie
-
July 13th, 2010, 07:13 PM
#3
Re: Unable to connect MySQL database. Weird _imp_ problem
I've checked "mysql_driver.h", and found these two functions :
(under public) static MySQL_Driver * Instance();
CPPCONN_PUBLIC_FUNC MySQL_Driver *get_mysql_driver_instance();
so, I've tried
driver=sql::mysql::get_mysql_driver_instance();
and I still get:
1>Ex1.obj : error LNK2001: 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)
-
July 13th, 2010, 07:32 PM
#4
Re: Unable to connect MySQL database. Weird _imp_ problem
 Originally Posted by skippergeffen
I've checked "mysql_driver.h", and found these two functions :
(under public) static MySQL_Driver * Instance();
CPPCONN_PUBLIC_FUNC MySQL_Driver *get_mysql_driver_instance();
Where are these functions implemented?.
All a header file does is make your code compile without errors, it doesn't help the linker find where those functions actually are. You called a function, and the linker is trying to find where the code for this function is. That is what I'm asking you to figure out.
To make my point more clear:
Code:
int SomeStupidFunction();
int main()
{
SomeStupidFunction();
}
This compiles, but where is the actual code to SomeStupidFunction? I called it, but where is it? All that first line does is declare the function so that the compiler doesn't give me a syntax error later on, that's all. When the linker now links the function, the linker needs to where the heck is the code to SomeStupicFunction.
Code:
int SomeStupidFunction();
int main()
{
SomeStupidFunction();
}
int SomeStupidFunction()
{
return 1;
}
Now this code not only compiles, it now links, because the linker found the implementation of the SomeStupidFunction() function.
The implementation could be in the same source file, a different source file, a library, another object module, etc...
Regards,
Paul McKenzie
Last edited by Paul McKenzie; July 13th, 2010 at 07:37 PM.
-
July 13th, 2010, 07:46 PM
#5
Re: Unable to connect MySQL database. Weird _imp_ problem
Well. since the connector doesn't consist of any .cpp's I guess it will be in
"mysqlcppconn.lib"
But I've already linked to that file.
I've trying working with this tutorial,
http://dev.mysql.com/doc/refman/5.1/...al-studio.html
both with the static and dynamic libaries, but still - nothing
-
July 13th, 2010, 08:06 PM
#6
Re: Unable to connect MySQL database. Weird _imp_ problem
 Originally Posted by skippergeffen
Well. since the connector doesn't consist of any .cpp's I guess it will be in
"mysqlcppconn.lib"
But I've already linked to that file.
If you already linked to it, then it would have been found. Since it wasn't found, then it isn't there.
So either you didn't link to it, or it isn't there. There is no third choice.
Furthermore, an extension of ".lib" can mean several things -- a static library, an import library.
both with the static and dynamic libaries, but still - nothing
It's either one or the other -- you can't specify both.
Regards,
Paul McKenzie
-
July 13th, 2010, 08:33 PM
#7
Re: Unable to connect MySQL database. Weird _imp_ problem
Yes but, look at steps 5-6 if what I did :
5. In Linker -> General -> Additional Libary Directories, I've added the "lib/opt" subfolder.
6. I've also added "mysqlcppconn.lib" under Linker -> Input -> Additional Dependencies
So I don't really see how could it possibly be linked incorrectly.
I just don't get it. I did it exactly as the manual in that link I gave you told to do it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|