c++有个新手。
我想为Raspi 3的C++开发准备工作环境,这包括C++ ( windows上的netbeans,Raspi上的geany ),mysql (mariDB)和QT。
第一步是在raspi上创建一个简单的脚本"hello world“,并在cppconn的帮助下进行构建。第二步是在Netbeans中的windows上创建相同的脚本,并在本地/远程构建它。
我有一个简单的脚本:
/*
* 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)对为C++编码设置Mysql感到非常沮丧。
(请提出建议:)
谢谢你,马立克
发布于 2017-11-06 07:59:52
为了更好的可读性,我对命令行和错误消息进行了重新格式化(具体来说,我使用了换行方式,并将通往ld的路径规范化)。
dist/Debug/MinGW_Qt-Windows/hello-world-7-pc-mysql \ g++ \ -o \Debug/MinGW_Qt-g++/-o/L/C/Program/MySQL/MySQL\ Connector\ C++\ 1.1.9/lib /L/C/Program/MySQL/MySQL\ Connector\ C++\ 1.1.9/g++/cppconn\-L/C/Program/MySQL/MySQL连接器C++\ 1.1.9/-olmysqlcppconn- -lmysqlcppconn \ -lmysqlcppconn /C/Program/MySQL/MySQL连接器C++ 1.1.9/lib/opt/mysqlcppconn-static.lib“\ "/C/Program /MySQL/ C++ 1.1.9/lib/opt/mysqlcppk.lib\-lmysqlcppconn无法找到-lmysqlcppconn静态c:/Qt/Qt5.9.2/ -lmysqlcppconn /i 686-W64-mingw32 32/bin/ld.exe:无法找到-lmysqlcppconn,-lmysqlcppconn无法找到-lmysqlcppconn
首先要说的是,ld未能找到调用-lmysqlconn的文件。这很奇怪,因为通常情况下,-l的意思是“用.a或.so类型加载名为libmysqlconn的库”。但是,关于命令行有一些非常奇怪的事情:
首先,-L是命令行选项,用于指定在哪里查找库(.lib、.so、.a、.dll) --那么为什么要指定include目录呢?
其次,为什么要同时指定-lmysqlconn-static和-lmysqlconn?您要么需要静态库,要么需要动态库--两者都不需要。
第三,为什么要显式地指定库名(在/C/...行中)。
第四,为什么要两次指定-lmysqlcppconn?
我认为您需要将命令行更改为如下所示:
g++ -o dist/Debug/MinGW_Qt-Windows/hello-world-7-pc-mysql \
-L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.9/lib \
-lmysqlcppconn \
build/Debug/MinGW_Qt-Windows/main.o最后,我认为您需要仔细阅读Qt教程。此刻,你似乎只是在四处乱晃。
https://stackoverflow.com/questions/47125796
复制相似问题