gpt4 book ai didi

c++ - 构建缺少错误 mysqlcppconn 的 C++ 脚本(没有这样的文件)

转载 作者:行者123 更新时间:2023-11-29 05:58:35 25 4
gpt4 key购买 nike

有一个 c++ 新手。

我想为 Raspi 3 的 C++ 开发准备工作环境。这包括 C++(windows 上的 netbeans IDE,Raspi 上的 geany)、mysql (mariDB) 和 QT。

第一步是在 raspi 上编写一个简单的脚本“hello world”,然后在 cppconn 的帮助下进行构建。第二步是在 Netbeans IDE 中的 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 感到非常沮丧。

请指教:)

谢谢,马立克

最佳答案

我重新格式化了您的命令行和错误消息以提高可读性(特别是我放入了换行符,并将路径规范化为 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”。但是,您的命令行有许多非常奇怪的地方:

首先,-L 是命令行选项,用于指定在哪里可以找到(.lib、.so、.a、.dll)——那你为什么要指定包含目录?

其次,为什么要同时指定 -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 教程。此刻,你似乎只是在四处游荡。

关于c++ - 构建缺少错误 mysqlcppconn 的 C++ 脚本(没有这样的文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47125796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com