Reputation: 41
I want to connect to my MySQL database with c++ with the mysql++ library (wrapper) in linux (ubuntu 12.04). I installed mysql via the xampp for linux, but also tried it with sudo apt-get istall mysql-server
. I got the mysql++ lib with sudo apt-get install libmysqlclient15-dev
.
The include statement include <mysql++/mysql++.h>
gave no warning, but when I'm trying to build my application, this is the compilation error:
In file included from /usr/include/mysql++/connection.h:38:0,
from /usr/include/mysql++/mysql++.h:56,
from /home/bert/Documents/QtProjecten/FGBG/modules/server/mysqldb.h:6,
from /home/bert/Documents/QtProjecten/FGBG/modules/server/mysqldb.cpp:1:
/usr/include/mysql++/common.h:131:28: fatal error: mysql_version.h: No such file or directory
compilation terminated.
Indeed there is no mysql_version.h
in the /usr/include/mysql++
directory. Does anybody have a clue what this means? I almost couldn't find any documentation on this matter and I even tried to copy the mysql_version.h
-file from /usr/include/mysql
to /usr/include/mysql++
.
Edit:
/usr/local/include/mysql++
and /usr/include/mysql++
. Could this be a problem?#include <mysql++/mysql++.h>
to </usr/include/mysql++/mysql++.h>
, didn't work.-DMYSQLPP_MYSQL_HEADERS_BURIED
or -I/usr/include/mysql
) in my Cmakelist, it doesn't recognize the mysqlpp
namespace anymore.Here is the code of my header file:
#ifndef MYSQLDB_H
#define MYSQLDB_H
#include <mysql++/mysql++.h>
class MySQLDB{
public:
MySQLDB();
~MySQLDB();
bool open(std::string dbname, std::string hostname, std::string username, std::string password);
mysqlpp::StoreQueryResult query(std::string sql);
bool close();
private:
mysqlpp::Connection conn;
};
#endif
Upvotes: 3
Views: 7314
Reputation: 214
Check if you can link mysqlpp namespace using,
dpkg -L libmysql++-dev
If yes, i.e. if you have libmysqlpp.a, link it using -lmysqlpp as following,
g++ sm_cpp.cpp -o test -I/usr/include/mysql++ -I/usr/include/mysql -lmysqlpp
It will work. The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name. include <mysql++.h>
- No such file or directory
Upvotes: 3
Reputation: 3782
Compile with the -DMYSQLPP_MYSQL_HEADERS_BURIED
flag, or include the mysql directory directly. I.e. try one of the following:
g++ test.cpp -o test -DMYSQLPP_MYSQL_HEADERS_BURIED
g++ test.cpp -o test -I/usr/include/mysql/
Both of these worked for me.
More information can be found in this bug report.
Upvotes: 1
Reputation: 75
mysql_version.h is part of mysql package, not mysqlpp package. Just include /usr/include/mysql or usr/local/include/mysql [ depends on where you istalled mysql dev files ] into your IDE. Easy solution (:
Upvotes: 1
Reputation:
If you build your own package it might be helpful to uninstall all related dev package from your system (mysql++).
Upvotes: 0