C++ with mysql

Pages: 12
Dear all,

I am trying to access a mysql DB by C++. I have found the following step to add mysql.h library. I am using Dev-c++, Windows Vista, and Appserv. So i cannot find C:\Program Files\MySQL\MySQL Server 5.0\lib\opt. In my mysql directory, there are only bin, data, scripts and share.
Please help because i cannot find guideline of adding mysql.h elsewhere.
Thank you very much.



1 - Download MySQL Server;
Download and install MYSQL Server (current version is 5.0) from http://www.mysql.com.
It is best to download the windows installer version.
During the install ensure that the C libray api is also installed as well (you may have to select custom install and ensure that it is selected for installation.
Install the server to the default directory C:\Program Files\MySQL\MySQL Server 5.0
test to make sure the server works fine using the test programs that comes with the server.
Check that the include and lib directorys are present.

2 Download and unpack the C++ library
You have already downloaded the C++ library. It would have unpacked the a folder called mysql++-3.0.6
I unpacked mine to the desktop - so my path to this folder is C:\Documents and Settings\andy\Desktop\mysql++-3.0.6

3 Setting up the library for DEV C++
DEV C++ uses mingw compiler. Mingw compiler uses the unix convention for naming libraries - so there is a special step that needs to be done first.
Look in the mysql++-3.0.6 folder for a file called README-MinGW.txt. Look for the section int that readme file called Prerequisite: MySQL C API DLL Import Library
Open a dos box and run the command as given in that section;
Make sure you use your path for where your mysql++-3.0.6 directory is.
So for me that command would look like this:
cd C:\Program Files\MySQL\MySQL Server 5.0\lib\opt
dlltool -k -d "C:\Documents and Settings\andy\Desktop\mysql++-3.0.\libmysqlclient.def" -l libmysqlclient.a

If you did that successfully, in the C:\Program Files\MySQL\MySQL Server 5.0\lib\opt directory you will see a file called libmysqlclient.a.

Now we can continue and build for DEVC++ and mingw.
Still in the dos box - change directories back to your mysql++-3.0.6
and run the command as given in the Building the Library and Example Programs of the README-MinGW.txt file (mingw32-make -f Makefile.mingw).

You shoulld see mingw compiling the library. Go and have a cofee.
Hopefully all will run well.

4 Moving the library (dll fiiles)
Look in the mysql++-3.0.6 directory for a file called install.hta.
Bouble click it to run it (it is an executable file).
A little program will pop up asking you where to to put the library files.
Just leave the the default location at C:\MySQL++ and use the check boxes to select how you want the subdirectorys laid out.
After pressing i-nstall now- you will find the directory C:\MySQL++
has been created.

Look inside this directory and you will see an include directory with the header files.
You will also see one called lib. look inside lib and you will see a mingw directory (if you also compile the VS2008 library you will see a subdirectory for this also).

Inside the mingw directory you will find two files libmysqlpp.a and mysqlpp.dll.

If you only plan to develop using DEVC++ and mingw - then copy mysqlpp.dll to the windows system32 directory.
(You can't do this if you plan to use VS2003/5/8 as well as mingw - because one of the dlls for VS2003/5/8 library has the same name).

I assume you know how to add additional include paths, and import libraries to DEV C++ projects.

Your two main guides for getting this whole thing setup is the
readme.txt and readme-mingw.txt files.
Good luck.
maximum168 wrote:
I am trying to access a mysql DB by C++. I have found the following step to add mysql.h library. I am using Dev-c++, Windows Vista, and Appserv. So i cannot find C:\Program Files\MySQL\MySQL Server 5.0\lib\opt. In my mysql directory, there are only bin, data, scripts and share.
Please help because i cannot find guideline of adding mysql.h elsewhere.


If you don't have the lib directory, then you have not setup mysql server 5.0 correctly with all the relevant files to do development.
All should not be lost. If you go to Control Panel ->Add Remove Programs, and select MYSQL, you should be able to use the modify option and select to add the Developer options.
Dear guestgulkan,

Because I am a beginner to write program about DB. I am still confused what i am doing.
I go to Control Panel -> Add Remove Programs but I cannot find Mysql in the list.

I installed the Apache, mysql, and php using package found from the web(appserv).

Thank you very much.
Having just gone on the web to checkout appserver - it seems to be a bundle that comes with apache, mysql, php etc..
I assume that app server has set itself up in a directory called c:\appserver
I assume that it has put mysql in c:\appserver\mysql and when you look in this mysql diectory, there is no include or opt subdirectories??

Am I right??

If so, then
Appserver does not provide the files for C development.
You can download the development files from the mysql website here:
http://dev.mysql.com/downloads/connector/c/6.0.html#Windows

Select the Windows MSI Installer (x86) option and save the download to your desktop
and we will continue from there...
I have downloaded the file you stated above, what i should do now?
Run it.
At the welcome to MYSQL Connector C screen, (after a few seconds while it checks for disk space) click [Next/b]
Accept the license agreement.
Click [b]nect

Click Change because we will want to change from the default setup options.

In the window make sure that you select the all library components to be installed on hard disk .
Click Browse if the default setup directory is not right and select the correct MYSQL directory for you. ( probably C:\appserv\mysql )
Click Next
Click [Install/b] - once set up has finished click [b]Finish
Now if you go to your mysql directory - you will find that a lib and an include
directory are now there.

If OK we will go on to the next step.




i have finished the setup :)
I see include and lib in the directory.
what's next?
Ok - we have have downloaded the C++ library - if you want to use a C++ approach,
then you can download a C++ wrapper library (whcih is what step 2 in your original post is all about).
have you already downloaded this C++ library?

This is also the fidddly bit.
will you be using mingw compiler or MSVC?
Last edited on
I am using Dev-C++, so i think it is mingw
I follow the instructions and type the followoing 2 lines into cmd but it shows error:

cd C:\Program Files\MySQL\MySQL Server 5.0\lib\opt
dlltool -k -d c:\mysql++\libmysqlclient.def -l libmysqlclient.a

Because I am using a Chinese version windows so i dunno how to translate the error into English. I think the meaning of the error is that the system dunno what "dlltool" is.
dlltool is in the mingw compiler bin directory.

Im my case as my mingw compiler is is c:\mingw directory, my dlltool command looks like

c:\mingw\bin\dlltool -k -d c:\mysql++\libmysqlclient.def -l libmysqlclient.a


((Also where did you put the C developer files you downloaded earlier?))

i put it on the desktop
i cannot find any directory named "mingw" or i cannot find any file named "dlltool".
So again, i should download it from the web?
so - you need a compiler - what compiler do you plan/want to use?
whatever,

let's choose mingw
Go here
http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=240780&release_id=595197

and download mingw5.1.4.exe, which is the automated installer (download it to your desktop or some where easily accessable).

Run it and as the various options screen come up:
Select the [bDownload and Install][/b] option
Accept the license agreement
Select current for the package type
Select Mingw base and g++ compiler and Mingwmake at the component screen
Accept the default directory of c:\mingw
Accept the default name of mingw as the start menu folder name
Click install and a couple of minute later you will have
a folder called c:\mingw will all the required subdirectors and files.
Total time from start of all this - about ten minutes.

finished the following 2 steps.

cd C:\Program Files\MySQL\MySQL Server 5.0\lib\opt
dlltool -k -d c:\mysql++\libmysqlclient.def -l libmysqlclient.a


what is the next step?
Thank you very much.
C:\MinGW\bin\mingw32-make -f Makefile.mingw

i tried this but it says that g++ is not internal or external something.
You should add C:\MinGW\bin\ (and probably C:\MinGW\include\ and C:\MinGW\lib\ ) directory to your path variable.
Dear guestgulkan,

I am in the step which i bold the line in the following. Could you tell me how to add library into Dev C++?

1 - Download MySQL Server;
Download and install MYSQL Server (current version is 5.0) from http://www.mysql.com.
It is best to download the windows installer version.
During the install ensure that the C libray api is also installed as well (you may have to select custom install and ensure that it is selected for installation.
Install the server to the default directory C:\Program Files\MySQL\MySQL Server 5.0
test to make sure the server works fine using the test programs that comes with the server.
Check that the include and lib directorys are present.

2 Download and unpack the C++ library
You have already downloaded the C++ library. It would have unpacked the a folder called mysql++-3.0.6
I unpacked mine to the desktop - so my path to this folder is C:\Documents and Settings\andy\Desktop\mysql++-3.0.6

3 Setting up the library for DEV C++
DEV C++ uses mingw compiler. Mingw compiler uses the unix convention for naming libraries - so there is a special step that needs to be done first.
Look in the mysql++-3.0.6 folder for a file called README-MinGW.txt. Look for the section int that readme file called Prerequisite: MySQL C API DLL Import Library
Open a dos box and run the command as given in that section;
Make sure you use your path for where your mysql++-3.0.6 directory is.
So for me that command would look like this:
cd C:\Program Files\MySQL\MySQL Server 5.0\lib\opt
dlltool -k -d "C:\Documents and Settings\andy\Desktop\mysql++-3.0.\libmysqlclient.def" -l libmysqlclient.a

If you did that successfully, in the C:\Program Files\MySQL\MySQL Server 5.0\lib\opt directory you will see a file called libmysqlclient.a.

Now we can continue and build for DEVC++ and mingw.
Still in the dos box - change directories back to your mysql++-3.0.6
and run the command as given in the Building the Library and Example Programs of the README-MinGW.txt file (mingw32-make -f Makefile.mingw).

You shoulld see mingw compiling the library. Go and have a cofee.
Hopefully all will run well.

4 Moving the library (dll fiiles)
Look in the mysql++-3.0.6 directory for a file called install.hta.
Bouble click it to run it (it is an executable file).
A little program will pop up asking you where to to put the library files.
Just leave the the default location at C:\MySQL++ and use the check boxes to select how you want the subdirectorys laid out.
After pressing i-nstall now- you will find the directory C:\MySQL++
has been created.

Look inside this directory and you will see an include directory with the header files.
You will also see one called lib. look inside lib and you will see a mingw directory (if you also compile the VS2008 library you will see a subdirectory for this also).

Inside the mingw directory you will find two files libmysqlpp.a and mysqlpp.dll.

If you only plan to develop using DEVC++ and mingw - then copy mysqlpp.dll to the windows system32 directory.
(You can't do this if you plan to use VS2003/5/8 as well as mingw - because one of the dlls for VS2003/5/8 library has the same name).

I assume you know how to add additional include paths, and import libraries to DEV C++ projects.

Your two main guides for getting this whole thing setup is the
readme.txt and readme-mingw.txt files.
Good luck.
Pages: 12