Sign in to follow this  
hkBattousai

MySQL Library Needed

Recommended Posts

I'm trying to write down my first MySQL database management program in C++ using DevCPP. I included mysql.h file, and then wrote my simple code. Compiler gave errors like this :
Quote:
[Linker Error] undefined reference to `mysql_init@4' [Linker Error] undefined reference to `mysql_real_connect@32' [Linker Error] undefined reference to `mysql_errno@4' [Linker Error] undefined reference to `mysql_error@4' [Linker Error] undefined reference to `mysql_errno@4' [Linker Error] undefined reference to `mysql_close@4'
Then I linked libmysql.lib, but it didn't work, it still gives the same errors. What library do I have to link in my project?

Share this post


Link to post
Share on other sites
From my knowledge, this kind of errors are given when the project needs one or more lib*.a files to be linked. I used to encounter similar errors when I first started to study OpenGL.

If it is so, what library file should I link? I tried libmysql.lib (this file is the one included in MySQL installation directory), but it didn't work.

System :
WinXP HE
Dev-C++
MySQL 5.1

Share this post


Link to post
Share on other sites
Quote:
Original post by Battousai
From my knowledge, this kind of errors are given when the project needs one or more lib*.a files to be linked. I used to encounter similar errors when I first started to study OpenGL.

If it is so, what library file should I link? I tried libmysql.lib (this file is the one included in MySQL installation directory), but it didn't work.

System :
WinXP HE
Dev-C++
MySQL 5.1


Maybe the .lib file is a Microsoft C++ lib file? Check if there is a libmysql.a somewhere.

Share this post


Link to post
Share on other sites
I found the solution on the net :
Quote:
Compiling in Dev-Cpp on Windows

1. get the pexports.
2. execute pexports on mysql library (libmysql.dll):
pexports libmysql.dll > libmysql.def
3. with dlltool (comes with mingw:
dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a
4. now, create a project, and in option\parameters\linker add -lmysql.
5. now, add the directories where are the mysql includes and lib (libmysql.a).
6. on linking, its has errors, as "mysql_init@4" not found. Enter in the libmysql.def and found mysql_init and put the @* that you are see. execute step 3 again.
7. now, its linking perfect, remember that the libmysql.dll need be in the ambient variable path, or in the windows\system32 or in directory of application that you are creating.


But there's another problem now.
dlltool.exe utility program doesn't produce a library file properly.

The command
shell> dlltool --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a -k
gives the output :
dlltool: _spawnvp
and two files are created during the process. One is dyykh.s (492 bytes), and the other one is libmysql.a (0 bytes).

Am I doing something wrong?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this