c ++有一个新手。
我想为Raspi 3的C ++开发准备工作环境。 这包括C ++(Windows上的netbeans IDE,Raspi上的geany),mysql(mariDB)和QT。
第一步是在raspi上创建一个简单的脚本“hello world”,并在cppconn的帮助下进行构建。 第二步是在Netbeans IDE中的Windows上制作相同的脚本,并在localy / remote中构建它。
我有这个简单的脚本:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: marek
*
* Created on 1. listopadu 2017, 22:33
*/
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
/*
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 <mysql_driver.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
cout << endl;
cout << "running select as a messege" << 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://10.0.0.6:3306", "root", "FTQERJSC");
/* Connect to the MySQL test database */
con->setSchema("mysql");
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;
std::cout << "hello world pc 5 mysql\n";
#ifdef __linux__
std::cout << "__linux__\n";
#elif defined(__unix__)
std::cout << "__unix__\n";
#elif defined(_WIN64)
std::cout << "_WIN64\n";
#elif defined(_WIN32)
std::cout << "_WIN32\n";
#endif
#if __WORDSIZE == 64
std::cout << "64 bit\n";
#else
std::cout << "32 bit\n";
#endif
return 0;
}
在构建期间,我遇到了这些错误:
cd 'C:\Users\marek\Documents\c++ projects\hello-world-7-pc-mysql'
C:\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/marek/Documents/c++ projects/hello-world-7-pc-mysql'
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_Qt-Windows/hello-world-7-pc-mysql.exe
make.exe[2]: Entering directory `/c/Users/marek/Documents/c++ projects/hello-world-7-pc-mysql'
mkdir -p dist/Debug/MinGW_Qt-Windows
g++ -o dist/Debug/MinGW_Qt-Windows/hello-world-7-pc-mysql build/Debug/MinGW_Qt-Windows/main.o -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.9/lib -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.9/include/cppconn -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.9/include -lmysqlcppconn-static -lmysqlcppconn "/C/Program Files/MySQL/MySQL Connector C++ 1.1.9/lib/opt/mysqlcppconn-static.lib" "/C/Program Files/MySQL/MySQL Connector C++ 1.1.9/lib/opt/mysqlcppconn.lib" -lmysqlcppconn
c:/Qt/Qt5.9.2/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lmysqlcppconn-static
c:/Qt/Qt5.9.2/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lmysqlcppconn
c:/Qt/Qt5.9.2/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lmysqlcppconn
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW_Qt-Windows/hello-world-7-pc-mysql.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/marek/Documents/c++ projects/hello-world-7-pc-mysql'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/marek/Documents/c++ projects/hello-world-7-pc-mysql'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 858ms)
Totaly对为C ++编码设置Mysql感到沮丧。
请指教:)
谢谢你, 马雷克
答案 0 :(得分:2)
我重新格式化了您的命令行和错误消息以提高可读性(特别是我放入换行符,并将路径标准化为ld
)。
g++ -o dist/Debug/MinGW_Qt-Windows/hello-world-7-pc-mysql \ build/Debug/MinGW_Qt-Windows/main.o \ -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.9/lib \ -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.9/include/cppconn \ -L/C/Program\ Files/MySQL/MySQL\ Connector C++\ 1.1.9/include \ -lmysqlcppconn-static \ -lmysqlcppconn \ "/C/Program Files/MySQL/MySQL Connector C++ 1.1.9/lib/opt/mysqlcppconn-static.lib" \ "/C/Program Files/MySQL/MySQL Connector C++ 1.1.9/lib/opt/mysqlcppconn.lib" \ -lmysqlcppconn c:/Qt/Qt5.9.2/Tools/i686-w64-mingw32/bin/ld.exe: cannot find -lmysqlcppconn-static c:/Qt/Qt5.9.2/Tools/i686-w64-mingw32/bin/ld.exe: cannot find -lmysqlcppconn c:/Qt/Qt5.9.2/Tools/i686-w64-mingw32/bin/ld.exe: cannot find -lmysqlcppconn
首先要说的是ld
无法找到调用-lmysqlconn
的文件。这很奇怪,因为通常-l
表示加载名为libmysqlconn
的库.a
或.so
&#34;。但是,您的命令行有很多非常奇怪的事情:
首先-L
是命令行选项,用于指定查找库(.lib,.so,.a,.dll)的位置 - 所以为什么要指定{{1}目录?
其次,为什么要同时指定include
和 -lmysqlconn-static
?您要么需要静态库,要么需要动态库 - 而不是两者。
第三,为什么要尝试明确指定库名称(在-lmysqlconn
行中)。
第四,为什么要指定/C/...
两次?
我认为您需要将命令行更改为:
-lmysqlcppconn
最后,我认为您需要仔细阅读Qt教程。此刻,你似乎只是四处乱窜。