MySQL Forums
Forum List  »  Connector/C++

Set up MySQL Connector/C++ with Code::Blocks on Debian
Posted by: Scott Griffith
Date: April 28, 2013 11:20AM

This post started as a rather silly question (through inexperience) about how to get the connector libraries working. So, as I've made some headway, I thought I'd edit it (heavily) so the information I've gleaned is up here for anybody else who needs it.

So I've been trying to learn how to use C++ and MySQL together. To that end, I have dusted off my C++ reference and installed Code::Blocks and the MySQL Connector/C++ on my Debian Wheezy (64-bit) system. It was a bit rocky at first, but I'm slowly getting somewhere (been a while since I did any coding).

If anybody knows of something I've done wrong, feel free to correct me, and I'll make sure to edit the post summore.

I installed Code::Blocks from the Debian repo.
I then downloaded the GA binary release mysql-connector-c++-1.1.3-linux-debian6.0-x86-64bit.tar.gz from mysql.com, extracted it, and placed the lib and include folders into my /usr/local/ folder under a subfolder called "mysql".

Ok, so that bit was really basic, so if you're lost, I'd suggest taking a look at a decent linux book. Don't know if it's the best, but I've been going through The Linux Bible.

Noticing that the examples are missing from the binary release, I also grabbed the source archives, so I could take a look at the examples. Note that examples.h has some useful #define lines for checking your compiler version so you can use "EXAMPLE_FUNCTION" in a try...catch error outputty-type thing. Again, if you're unfamiliar with try...catch and #define, I'd say go grab a book on C++.

On to Code::Blocks. I created a new console application project, "MySQLTest", using the GNU GCC Compiler, and replaced the "Hello World" code it gave me in main.cpp with the code from standalone_example.cpp, and copied over exmaples.h to the project dir, slapping an include line at the top of main.cpp for it.

The next bit I did was create a global variable in Code::Blocks (Settings/Global Variables), called "mysql", with the base dir being "/usr/local/mysql" (which is probably not all that great, because there's nothing there), the include dir being "/usr/local/mysql/include", and the lib dir being "/usr/local/mysql/lib".

After that I set some build options (Project/Build Options". I selected the root node in the tree on the left of the dialog, and in the "Compiler" tab within "Search Directories" I added "$(#mysql.include)" - thus making use of the global variable I made, and I put "$(#mysql.lib)" as an entry in the "Linker" tab.

Right. So I want to build a static binary, simply because it means I don't have to faff about quite so much if I want to run my program on another machine. And to get this to work, it seems I need to do the following.

In the aforementioned Linker tab, I added "/usr/lib/x86_64-linux-gnu" so that the compiler can find one of the .a files (libmysqlclient.a) needed for the static build. This folder will probably be different if you're not on a 64-bit Debian system like me.

Then in the left pane of the "Linker Settings" tab, I added "libmysqlclient.a" and also "libmysqlcppconn-static.a", which is in the "lib" directory of the connector.

Note that (for me at least) "libmysqlclient.a" needs to be in the list above "libmysqlcppconn-static.a", or you get a ton of linker errors.

And that's it! All I (and probably you if you had to read this post) have to do now is read the manuals on how to use the connector.

- Scott



Edited 2 time(s). Last edit at 05/06/2013 10:17AM by Scott Griffith.

Options: ReplyQuote


Subject
Views
Written By
Posted
Set up MySQL Connector/C++ with Code::Blocks on Debian
11941
April 28, 2013 11:20AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.