problem building dll with mysql

All things related to advanced DLL development. <br>
Exchange c/c++ source code with other members.

problem building dll with mysql

Postby ndogg » 2010 Feb 05 Fri 1:57:31 am

hey guys, I'm working on windows 7 (64bit) and developing with code::blocks (mingw compiler). I'm using the mysql/c++ connector from the mysql website to interface my code with mysql. What's puzzling is that the code compiles fine (although with a couple seemingly irrelevant warnings), but when I try to use the command line g++ to create a dll from the whuser.o file it gives a few errors regarding mysql. The command I type is "g++ -shared -o whuser.dll whuser.o". I receive the following 5 error messages in response:

C:\Users\nate\Desktop\auto>g++ -shared -o whuser.dll .\Release\whuser.o
.\Release\whuser.o:whuser.cpp:(.text+0x569): undefined reference to `__imp__get_
driver_instance'
.\Release\whuser.o:whuser.cpp:(.text+0xf40): undefined reference to `__imp__get_
driver_instance'
.\Release\whuser.o:whuser.cpp:(.text+0x16a0): undefined reference to `__imp__get
_driver_instance'
.\Release\whuser.o:whuser.cpp:(.text+0x1d90): undefined reference to `__imp__get
_driver_instance'
.\Release\whuser.o:whuser.cpp:(.text+0x248b): undefined reference to `__imp__get
_driver_instance'
collect2: ld returned 1 exit status

The function "get_driver_instance" is referenced in a couple of the included mysql header files, and from what I gather the function is defined in the mysql library "mysqlcppconn.lib". I don't understand why g++ seems to find the function definition during compilation, but then doesn't when I try to use the command line to create the dll. I've tried explicitly linking the library with -l or -L in the command line arguments, but it has had no effect. I've found this issue on google, but only regarding compilation (not dll creation) so people just say that the mysql library is missing. This is driving me nuts, if anyone could help it would be greatly appreciated.

-Nate
ndogg
One Pair
 
Posts: 8
Joined: 2008 Oct 24 Fri 5:19:03 am

Re: problem building dll with mysql

Postby support » 2010 Feb 05 Fri 8:10:03 am

ok first step is to compile a simply hello world .exe from within your dev. environment that correctly finds and binds your mysql stuff.

once you do this you'll have a baseline and then you can attempt to step to the .dll

8)
The live game is owned by humans.
The online game is owned by humans with computers.
User avatar
support
Site Admin
 
Posts: 11722
Joined: 2004 Sep 23 Thu 12:07:14 pm
Location: US

Re: problem building dll with mysql

Postby ndogg » 2010 Feb 05 Fri 11:29:18 am

ok, I tried to make an executable using the following command:
g++ whuser.cpp -o whuser.exe

I received similar error messages:

C:\Users\nate\Desktop\auto>g++ whuser.cpp -o whuser.exe
whuser.cpp: In function `int bet(double)':
whuser.cpp:62: warning: converting to `int' from `double'
C:\Users\NATE~1\AppData\Local\Temp/ccHOplYS.o:whuser.cpp:(.text+0x227): undefi
ned reference to `__imp__get_driver_instance'
C:\Users\NATE~1\AppData\Local\Temp/ccHOplYS.o:whuser.cpp:(.text+0x7f9): undefi
ned reference to `__imp__get_driver_instance'
C:\Users\NATE~1\AppData\Local\Temp/ccHOplYS.o:whuser.cpp:(.text+0xdcb): undefi
ned reference to `__imp__get_driver_instance'
C:\Users\NATE~1\AppData\Local\Temp/ccHOplYS.o:whuser.cpp:(.text+0x1440): undef
ined reference to `__imp__get_driver_instance'
C:\Users\NATE~1\AppData\Local\Temp/ccHOplYS.o:whuser.cpp:(.text+0x1fac): undef
ined reference to `__imp__get_driver_instance'
C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../li
bmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
ndogg
One Pair
 
Posts: 8
Joined: 2008 Oct 24 Fri 5:19:03 am

Re: problem building dll with mysql

Postby support » 2010 Feb 05 Fri 7:31:30 pm

ok a hello world program is NOT whuser.dll
just try compiling this code using your mysql stuff

Code: Select all
#include <stdio.h>
int main( int argc, char* argv[] )
{
    printf("hello world\n");
    return 0;
}
The live game is owned by humans.
The online game is owned by humans with computers.
User avatar
support
Site Admin
 
Posts: 11722
Joined: 2004 Sep 23 Thu 12:07:14 pm
Location: US

Re: problem building dll with mysql

Postby ndogg » 2010 Feb 09 Tue 12:04:09 am

sorry about that, I gotcha now. So, here's the entirety of the hello world program w/ basic mysql stuff:

#include <stdio.h>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <C:\Users\nate\Desktop\auto\cppconn\driver.h>
#include <C:\Users\nate\Desktop\auto\cppconn\exception.h>
#include <C:\Users\nate\Desktop\auto\cppconn\resultset.h>
#include <C:\Users\nate\Desktop\auto\cppconn\statement.h>
#include <C:\Users\nate\Desktop\auto\cppconn\prepared_statement.h>

using namespace std;
using namespace sql::mysql;
using namespace sql;

sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;

int main( int argc, char* argv[] )
{
driver = get_driver_instance();

printf("hello world\n");
return 0;
}

Before I inserted the "driver = get_driver_instance();" line, codeblocks not only compiled fine but also successfully created an .exe file (it didn't create the .exe during the build on the whuser file, I suppose because the hello world file has a main method and the whuser file doesn't?). When I inserted the "driver = get_driver_instance();" line, I received the same error message as before:
C:\Users\nate\Desktop\auto\test.o:test.cpp:(.text+0x129)||undefined reference to `__imp__get_driver_instance'|

I've tried using the other syntactic variations found in the mysql reference manual for the mysql connector/c++, but with the same result. I've also made sure to add the two mysql libraries that came with the connector to codeblock's link libraries section...no change. The only suggestions from google are that the mysql libraries aren't being properly linked...but have yet to find a fix that works. Thanks again for the help,
Nate
ndogg
One Pair
 
Posts: 8
Joined: 2008 Oct 24 Fri 5:19:03 am

Re: problem building dll with mysql

Postby support » 2010 Feb 09 Tue 1:55:17 am

an undefined reference is definitely a link error. so you're either calling it wrong (incorrect name/spelling, etc.) or your project isn't linking it.

8)
The live game is owned by humans.
The online game is owned by humans with computers.
User avatar
support
Site Admin
 
Posts: 11722
Joined: 2004 Sep 23 Thu 12:07:14 pm
Location: US

Re: problem building dll with mysql

Postby ndogg » 2010 Feb 10 Wed 12:02:11 am

sure...the problem is that I'm not calling it wrong (according the the mysql manual), and I've instructed the compiler to link to the only two libraries that came with the mysql-c++ connector package (and as you can see from the command line output, the compiler is referencing those libraries). No luck from the mysql forum yet either. I guess I'll probably have to use a different database engine.
ndogg
One Pair
 
Posts: 8
Joined: 2008 Oct 24 Fri 5:19:03 am

Re: problem building dll with mysql

Postby support » 2010 Feb 12 Fri 1:23:55 am

ndogg wrote:sure...the problem is that I'm not calling it wrong (according the the mysql manual), and I've instructed the compiler to link to the only two libraries that came with the mysql-c++ connector package (and as you can see from the command line output, the compiler is referencing those libraries). No luck from the mysql forum yet either. I guess I'll probably have to use a different database engine.


or forget trying to talk directly to the local db engine and just use the ip interface.

or run a local webserver and write your db access in .php and then talk to your local web pages from within your .dll

8)
The live game is owned by humans.
The online game is owned by humans with computers.
User avatar
support
Site Admin
 
Posts: 11722
Joined: 2004 Sep 23 Thu 12:07:14 pm
Location: US


Return to whuser.dll

Who is online

Users browsing this forum: No registered users and 1 guest