c++ - QT MYSQL驱动构建, undefined reference `mysql_get_client_version@0'

标签 c++ mysql qt qt5 qmake

我正在尝试构建QMYSQL驱动,我遵循文档( https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows )

它建议我运行代码:

cd %QTDIR%\qtbase\src\plugins\sqldrivers
qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt"
nmake sub-mysql

mysql“自定义安装”中没有“库和包含文件”模块,因此我从sql服务中选择该文件夹。

我在cmd上运行代码:

cd C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers
qmake --  "MYSQL_INCDIR=C:/MySql/MySQL Server 8.0/include" "MYSQL_LIBDIR=C:/MySql/MySQL Server 8.0/lib"

结果是:

info: creating stash file C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\.qmake.stash

Running configuration tests...
Checking for DB2 (IBM)... no
Checking for InterBase... no
Checking for MySQL... no
Checking for OCI (Oracle)... no
Checking for ODBC... yes
Checking for PostgreSQL... no
Checking for SQLite (version 2)... no
Checking for TDS (Sybase)... no
Done running configuration tests.

Configure summary:

Qt Sql Drivers:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... yes
  PostgreSQL ............................. no
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... no

Qt is now configured for building. Just run 'mingw32-make'.
Once everything is built, you must run 'mingw32-make install'.
Qt will be installed into 'C:\Qt\5.12.6\mingw73_32'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

好像没有检测到mysql。我应该怎么做才能构建mysql驱动。

我检查了 qmake 的配置日志:

    Trying source 5 (type inline) of library mysql ...
+ cd /d C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && C:\Qt\5.12.6\mingw73_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "QMAKE_USE += mysql" "QMAKE_LIBS_MYSQL = \"C:/MySql/MySQL Server 8.0/lib/libmysql.lib\"" "QMAKE_INCDIR_MYSQL = \"C:/MySql/MySQL Server 8.0/include\"" C:/Qt/5.12.6/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql
> Info: creating stash file C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\config.tests\.qmake.stash
+ cd /d C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && set MAKEFLAGS=& mingw32-make
> g++ -c -fno-keep-inline-dllexport -O2 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -I"C:\MySql\MySQL Server 8.0\include" -IC:\Qt\5.12.6\mingw73_32\mkspecs\win32-g++  -o main.o main.cpp
> g++ -Wl,-s -Wl,-subsystem,console -mthreads -o mysql.exe main.o  -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.6.11-win32\lib -LC:\Utils\postgresql\pgsql\lib "C:\MySql\MySQL Server 8.0\lib\libmysql.lib"   
> c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: main.o:main.cpp:(.text.startup+0xc): undefined reference to `mysql_get_client_version@0'
> collect2.exe: error: ld returned 1 exit status
> mingw32-make: *** [Makefile:66: mysql.exe] Error 1

我认为这是我的问题

undefined reference to `mysql_get_client_version@0'

但我不知道如何解决它。我确信“include”文件夹中有一个带有方法的“mysql.h”文件

unsigned long STDCALL mysql_get_client_version(void);

最佳答案

我解决了。

我解决了qmake是86X,服务器是64X。更改 64X qmake 有效

这个文档比旧的更好。

https://doc-snapshots.qt.io/qt5-5.14/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows

关于c++ - QT MYSQL驱动构建, undefined reference `mysql_get_client_version@0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59545414/

相关文章:

PHP - 列计数与值计数不匹配。

mysql - R Shiny 应用程序中的 SQL 查询语法 - CAST

c++ - 绑定(bind)的 c++ 值未在 QML 中更新

c++ - 在笛卡尔二维空间的每个象限中找到最近的点

python - 类交叉引用?

c++ - STL map<string, string>,给key赋0值导致编译错误

c++ - Visual Studio C++ - 像在 Eclipse 中一样在鼠标悬停时显示函数代码

MySQL 具有 SUM(column1) <> column2 不起作用

c++ - 如何检查两个 QLineEdit 如果它们不为空

c++ - 如何使用 QRegExp 从 QString 中获取子字符串?