MySQL Forums
Forum List  »  Connector/C++

Re: Mysql/mysql++ and C++
Posted by: Gordon Leonard
Date: July 16, 2007 03:51PM

I've just managed to achieve what you want after a day of playing under Mysql 5.046 or something (it doens't work under 5.1.x), mysql++ 3.2.3 on FC6 and found it wasn't too difficult (after much cursing of course). I didn't use the util.cpp etc stuff, instead i ripped out the very basic stuff and stuck in parameters directly in to con.connect(db,host,user,pwd), you have to use the full set of parameters if you need to specify the location of the socket if it is not default. i used one file similar to this:

#include<mysql.h>
#include<mysql++.h>

using namespace std;

int main(void)
{
mysqlpp::Connection con(false);
con.connect("test","localhost","username","password");
if(con)
{
printf("Connected to database.\n");
}
else
{
printf("Unable to connect to database.\n");
}
}



first of all, it took me a while, but i installed mysql++ from the source without errors. the hardest part I found was compiling my source.cpp with g++. i think the error you are getting is because 'it' can't find either -lmysqlclient or -lmysqlpp. i used something similar to this, as you basically did. i'm no linux expert and used a bit of trial and error to get the libraries to link which is why i am waffling a bit!!

g++ -I/usr/local/mysql/include -I/usr/local/mysql++-2.3.2/lib -o output -L/usr/local/mysql/lib -lmysqlclient -lmysqlclient_r -lmysqlpp mysource.cpp

i added /usr/local/mysql/lib and /usr/local/lib in to /etc/ld.so.conf.d/ (then ran ldconf ) which then fixed the error: "error while loading shared libraries: libmysqlpp.so.2: cannot open shared object file: No such file or directory" that you might get

i'll double check in the monring, it's getting late


somewhere in their example you are supposed you run a command which creates a db for you to use. as i said, it is easier to create your own. read the pdf, refman (??) which list the arguments you need to supply to connection. god love object orientated programming (i don't ahve a clue!!)



Edited 1 time(s). Last edit at 07/17/2007 01:54AM by Gordon Leonard.

Options: ReplyQuote


Subject
Views
Written By
Posted
7334
July 01, 2007 08:23AM
Re: Mysql/mysql++ and C++
4665
July 16, 2007 03:51PM


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.