MySQL++ in Windows Environment

Hey guys,
I have recently been looking for a way to store data on a server that I can connect to and pull data from using C++. I decided to go with MySQL. My issue is that there really isn't any good documentation on how to do this inside Windows. I would like to use DEVC++ if possible, but I do have visual studio 2008. I have compiled the lib in Visual Studio, but even when I link it it still cannot find Mysql++.h, printdata.h and command.h. I assume that all these are in the libraries that I compiled and linked.

Can anyone point me in the right direction? Also, would it be easier to just use the C API instead? Keep in mind I have never done any C Programming, just C++.

Extreme Thanks to anyone who can help me out with this.
Try removing the .h and see if it works.
good suggestion... also, if you have done c++, you have programmed in c. c++ is really only an extension of what c can do. i think maybe you mean that everything you've written is object oriented? this is a major feature of c++, but variable declarations, general syntax, etc... it's really c, with some added keywords, and a better memory management method for dynamic memory, and object oriented capabilities. If you want to have a better understanding of C, and where c++ is derived from, check out <http://publications.gbdirect.co.uk/c_book/>. There is also a great deal of information on this site as well.

take care
Which version of the mysql C++ library did you download.

I just downloaded the latest version from the mysql website and got it working with no problems.

So if you explain your current setup and what you have done so far maybe I can give you some help , or I can tell you how I did my setup.
please guestgulken, tell me how you did yours. I compiled the mysql files, (wellI think I did) and got the lib file. then I went to project -> properties -> c/c++ -> and added them to the Lib.

do I need anything else?

Here is my code, Also where is printdata, and cmdline.h? This file was one of the tutorials on the site.

#include "cmdline.h"
#include "printdata.h"

#include <mysql++>

#include <iostream>
#include <iomanip>

using namespace std;

int
main(int argc, char *argv[])
{
// Get database access parameters from command line
const char* db = 0, *server = 0, *user = 0, *pass = "";
if (!parse_command_line(argc, argv, &db, &server, &user, &pass)) {
return 1;
}

// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
for (size_t i = 0; i < res.num_rows(); ++i) {
cout << '\t' << res[i][0] << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return 1;
}

return 0;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return 1;
}
}
Also, if anyone knows how to do this in DevC++ I would greatly appreciate it.
Ah, I see what is going on with these headers.
Looks like you are using the same mysl C++ libray that I downloaded (mysql++-3.0.6.tar.gz ???).

When you unpacked the mysql++-3.0.6.tar.gz file, It created a directory, with loads of folders in it with loads of redme files, VC2008 project folder, etc...
Is that right??

You will see a folder called examples. Look inside this folder.

The files from the tutorials/examples shown on the website are the files from the example folder. You should see four header files including printdata.h in there along with the tutorial source files.


Last edited on
Wow, thanks. Ok, so now it knows where printdata, and cmdline are, but it can't find MySql++. How did you compile the libs, and can you tell me how you linked them?
OK - here we go - .

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.

Last edited on
PS - I forgot to say, that some of the header files you require to bulild programs using the C++ libary are in the C:\Program Files\MySQL\MySQL Server 5.0\include\ directory
(these header files are common both for C and C++ building).
Last edited on
Topic archived. No new replies allowed.