# MySQL Library Needed

This topic is 4034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
Quote:
 Original post by BattousaiFrom 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 HEDev-C++MySQL 5.1

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

##### Share on other sites
I found the solution on the net :
Quote:
 Compiling in Dev-Cpp on Windows1. get the pexports.2. execute pexports on mysql library (libmysql.dll):pexports libmysql.dll > libmysql.def3. with dlltool (comes with mingw:dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a4. 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?

• 37
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631362
• Total Posts
2999564
×