-
编译前准备工作:
- 下载QT5.11.1
https://download.qt.io/archive/qt/5.11/5.11.1/
- 下载Python:
https://www.python.org/downloads/
- 下载Perl:
https://www.activestate.com/activeperl/downloads
- 下载Ruby:
https://rubyinstaller.org/downloads/
- mingw32编译器选择:
根据QT官网给出的QT安装包抓到信息QT5.11.1是用 gcc5.3.0的编译器
mingw官网下载链接:http://mingw-w64.org/doku.php/download mingw-w64-install.exe)
配置成:i686-5.3.0-posix-dwarf-rt_v4-rev0
QT官网下载源码包:http://mirrors.ustc.edu.cn/qtproject/archive/qt/5.11/5.11.1/single/qt-everywhere-src-5.11.1.zip
按照常规编译出现的问题:
Project ERROR: Library 'mysql' is not defined.
- 解决方案:
一.静态局部编译:
1.由于本地电脑的mysql与QT中的Mysql库不匹配,需要重新编译
2.下载(https://downloads.mysql.com/archives/c-c/)mysql-connector-c-6.1.11-win32.msi安装到
C:/mysql/ 目录下
3.配置sqldriver/mysql/mysql.pro工程文件
a.注释掉 #QMAKE_USE += mysql
b.增加如下:
CONFIG += release
CONFIG += static
CONFIG += debug
QTPLUGIN: QSQLMYSQLS
INCLUDEPATH += C:/mysql/include/
win32: LIBS += -LC:/mysql/lib/ -lmysql
#1. You need to use libmysql.lib if you intend to give the libmysql.DLL along with your application.
#2. You need mysqlclient if you intend to distribute your application as standalone. The size of executable may increase.
#win32: LIBS += C:/mysql/lib/vs14/mysqlclient.lib
4.把qmake添加到window环境变量中,重启电脑
5.然后进入..\qt-everywhere-src-5.11.1\qtbase\src\plugins\sqldrivers\mysql
qmake mysql.pro
6.mingw32-make
7.mingw32-make install 执行该命令会自动把qsqlmysql.dll qsqlmysqld.dll两个文件添加到qmake所在的QT版本 中..\Qt\Qt5.11.1\5.11.1\mingw53_32\plugins\sqldrivers目录下
二.静态全局编译:
./configure.bat -static -debug-and-release -platform win32-g++ -prefix "C:\Qt\Qt5.11.1_MinGW_static" -no-sql-odbc -no-sql-sqlite -sql-mysql MYSQL_INCDIR=C:\mysql\include\ MYSQL_LIBDIR=C:\mysql\lib\ MYSQL_LIBS="-lmysql" -opengl desktop -opensource -confirm-license -nomake examples -nomake tools -nomake tests -recheck-all
1)如果修改配置内容,需要增加命令重新检查修改一遍相关的内容 -recheck-all
2)遇到odbc编译失败,去掉odbc 增加配置命令 -no-sql-odbc