如何在qt上build Mysql drive 35C

楼主系统是win10,最近在研究mysql和qt。

我在尝试用qt连接mysql服务器的时候,
qt creator 告诉我说mysql drive no lead.
我去qt 的论坛上面问,人家说现在已经qt不提供mysql的drive,想用要自己搭。给我一个官方的文档,https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows。

问题是,写文档的人估计很久没有装过mysql了,mysql安装器的Custom Install,已经没有Libs & Include Files的选项了。所以我很难确定如何执行cmd代码

cd %QTDIR%\qtbase\src\plugins\sqldrivers

qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt"

最后,我选择使用mysql server的文件,

cd %QTDIR%\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.

我检查了一下qmake log

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/lib/libmysql.lib" "QMAKE_INCDIR_MYSQL = C:/MySQL/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 -IC:\MySQL\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\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'

mysql看起来并没有进去。有没有熟悉mysql和qt的大佬解答一下。多谢了和最近有用qt的大佬解答一下。

1个回答

mysql的安装包自带驱动,安装步骤:
https://www.cnblogs.com/wlcaption/p/4265262.html

qq_42225882
qq_42225882 报错,:-1: error: Library 'mysql' is not defined.我主要问题是不知道include文件从哪里找
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问