繁体   English   中英

使用mysql连接器构建程序时出错

[英]Error Building Program with mysql connector

我有以下编译时错误我找不到原因:致命错误:mysql_connection.h:没有这样的文件或目录

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}

我在Codeblocks中编译它并且我已经安装了mysql连接器我正在尝试它第一次请求帮助!

您很可能缺少libmysqlcppconn-dev。 安装后,错误应该消失。

我遇到了和你一样的问题,但是在QtCreator的MAC上。 我收到的所有内容都是: cppconn/connection.h file is not found

我还没有连接MySQL服务器。 所以我评论了所有与数据库有关的文件。 建设我得到:

library -lGL not found

因为数据库是在linux上设置的,所以我不得不更改库。 所以我下载了第一个MAC的mysql库:

brew install mysql-connector-c++

然后我在.pro中添加了它们:

mac: {
   LIBS += -framework OpenGL
   INCLUDEPATH += /usr/local/opt/mysql-connector-c++/include/cppconn
}  

编译后我得到了错误:

boost/scopped_ptr.hpp file not found

在这里我需要安装boost:

brew install boost

然后在.pro中添加boost:

mac: {
   LIBS += -framework OpenGL
   INCLUDEPATH += /usr/local/opt/mysql-connector-c++/include/cppconn /usr/local/opt/boost/include
}

现在我再次出现错误:

symbol(s) not found for architecture x86_64
linker command failed with exit code 1

更新:

所以我的.pro在最后看起来像这样:

unix:!macx {
     LIBS += -lGL
     LIBS += -L/usr/lib -L/usr/lib -lmysqlcppconn
     INCLUDEPATH += -I/usr/include -I/usr/local/include -I/usr/local/include/cppconn
}

macx: {
    LIBS += -framework OpenGL -L/usr/local/opt/mysql-connector-c++/lib -lmysqlcppconn
    INCLUDEPATH += /usr/local/opt/mysql-connector-c++/lib
    INCLUDEPATH += /usr/local/opt/mysql-connector-c++/include/cppconn /usr/local/opt/boost/include /usr/local/opt/mysql-connector-c++/include
}

它似乎在INCLUDEPATH for macx我需要提到缺少的库mysqlcppconn -l有助于弄清楚这是库的名称。

它实际上工作。 现在所需要的只是与服务器的连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM