Sunday, June 12, 2011

C++ And Mysql for CodeBlocks MinGW

As far as I know, Mysql Library is not installed automatically for CodeBlocks. Follow some procedures bellow carefully to include mysql library for C++ projects :
  1. Open Site: devpaks.org/.
  2. Download libmysql 5.0.5-1sid, hope this library works on Mysql6.
  3. Rename libmysql-5.0.5-1sid.devpak to file .tar.bz2 extension, then uncompress it with 7Zip or winrar.
  4. Create an empty folder an name it with mysql.
  5. Copy the whole folder include to folder mysql where just created.
  6. Copy that folder mysql dan paste into folder include of MinGW, usually in C:\CodeBlocks\MinGW\include.
  7. Copy files in folder lib to folder lib of MinGW, usually in C:\CodeBlocks\MinGW\lib.
  8. Copy file .dll in folder bin to folder where the .exe source code whould build for your project.
  9. Dont forget to install MySQL befor. (XAMPP recommended).

Lets make some test to make sure that library works:
  1. Make a New CodeBlocks console program.
  2. Copy the content of mysql.cpp which located under folder example of uncompressed file .devpak to your new console program.
  3. Edit Host, User, Pass, Db options to meet your Mysql specification.
  4. Lets link Mysql library to our program :
    • Click CodeBlocks Menu Settings -> Compiler And Debugger -> Global Compiler Settings -> Search Directories Complier: Add C:\Program Files\MySQL\MySQL Server 5.1\include or wherever mysql.h is located.
    • Click CodeBlocks Menu Setting -> Compiler And Debugger -> Global Compiler Settings -> Linker Settings -> Link Libraries: add C:\Program Files\MySQL\MySQL Server 5.1\lib\debug\libmysql.lib or whatever libmysql.lib full path is located.
  5. Type F9 to build and run the program.
Good Luck.