【发布时间】:2013-08-18 04:53:12
【问题描述】:
我想用 c++ 和 linux (ubuntu 12.04) 中的 mysql++ 库(包装器)连接到我的 MySQL 数据库。我通过 xampp for linux 安装了 mysql,但也尝试使用 sudo apt-get istall mysql-server。我得到了带有sudo apt-get install libmysqlclient15-dev 的mysql++ 库。
include 语句include <mysql++/mysql++.h> 没有给出警告,但是当我尝试构建我的应用程序时,这是编译错误:
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.
在/usr/include/mysql++ 目录中确实没有mysql_version.h。有人知道这意味着什么吗?我几乎找不到任何关于这件事的文档,我什至尝试将mysql_version.h-文件从/usr/include/mysql复制到/usr/include/mysql++。
编辑:
- 我的文件系统中有两个 mysql++ 目录:
/usr/local/include/mysql++和/usr/include/mysql++。这可能是个问题吗? - 我把
#include <mysql++/mysql++.h>改成了</usr/include/mysql++/mysql++.h>,没用。 - 当我在 Cmakelist 中更改 GXX 标志(
-DMYSQLPP_MYSQL_HEADERS_BURIED或-I/usr/include/mysql)时,它不再识别mysqlpp命名空间。
这是我的头文件的代码:
#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
【问题讨论】: