软件:QT SDK v1.2.1 (Qt4.8.1),mysql:mysql-installer-community-5.5.28.3,安装网上指点安装,内含 .../include;.../lib等必要目录;操作系统win7 64位
参考:
Qt4 OpenSource for mingw中编译MySQL驱动 http://www.qtcn.org/bbs/read-htm-tid-4210.html,
其中:cd c:\mysql\lib
reimp -d libmysql.lib
dlltool -k -d libmysql.def -l libmysql.a
这一步没有问题,可以生成。
然后在dos模式下,进入c: /Qt/QtSDK/QtSources/4.8.1/src/plugins/sqldrivers/mysql
运行:qmake -o Makefile "INCLUDEPATH+=C:\mysql55\clude" "LIBS+=C:\mysql55\lib\libmysql.a" mysql.pro
正常生成Makefile文件;
运行:mingw32-make 后,
出现如下错误:
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1272: undefined reference to `mysql_init@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1272: undefined reference to `mysql_real_connect@32'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1287: undefined reference to `mysql_select_db@8'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1290: undefined reference to `mysql_close@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1296: undefined reference to `mysql_options@12'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1309: undefined reference to `mysql_set_character_set@8'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1301: undefined reference to `mysql_close@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1317: undefined reference to `mysql_get_client_version@0'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1317: undefined reference to `mysql_get_server_version@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1323: undefined reference to `mysql_thread_init@0'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver5closeEv':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1336: undefined reference to `mysql_thread_end@0'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1338: undefined reference to `mysql_close@4'
debug/qsql_mysql.o: In function `ZNK12QMYSQLDriver6tablesEN4QSql9TableTypeE':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1354: undefined reference to `mysql_get_server_version@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1362: undefined reference to `mysql_list_tables@8'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1366: undefined reference to `mysql_data_seek@12'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1367: undefined reference to `mysql_fetch_row@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1373: undefined reference to `mysql_free_result@4'
debug/qsql_mysql.o: In function `ZNK12QMYSQLDriver6recordERK7QString':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1426: undefined reference to `mysql_list_fields@12'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1432: undefined reference to `mysql_fetch_field@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1434: undefined reference to `mysql_free_result@4'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver16beginTransactionEv':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1452: undefined reference to `mysql_query@8'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver17commitTransactionEv':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1469: undefined reference to `mysql_query@8'
debug/qsql_mysql.o: In function `ZN12QMYSQLDriver19rollbackTransactionEv':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1486: undefined reference to `mysql_query@8'
debug/qsql_mysql.o: In function `ZNK12QMYSQLDriver11formatValueERK9QSqlFieldb':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/my
sql/qsql_mysql.cpp:1512: undefined reference to `mysql_real_escape_string@16'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\qsqlmysqld4.dll] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/QtSDK/QtSources/4.8.1/src/plugins/sqld
rivers/mysql'
mingw32-make: *** [debug] Error 2
参考:Windows下编译MYSQL驱动最简单的方法 http://www.qtcn.org/bbs/read-htm-tid-51060.html
依然出现类似错误:
\Qt\QtSDK\Desktop\Qt\4.8.1\mingw\lib" debug\qsqlmysqld_resource_res.o c:/mysql55/lib/libmysql.a -LC:/mysql55/lib/ -llibmysql -lQtSqld4 -lQtCored4
Creating library file: debug\libqsqlmysqld4.a
debug/qsql_mysql.o: In function `codec':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:224: undefined reference to `mysql_character_set_name@4'
debug/qsql_mysql.o: In function `qMakeError':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:235: undefined reference to `mysql_error@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:238: undefined reference to `mysql_errno@4'
debug/qsql_mysql.o: In function `qMakeStmtError':
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:310: undefined reference to `mysql_stmt_error@4'
C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:313: undefined reference to `mysql_stmt_errno@4'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:359: undefined reference to `mysql_stmt_result_metadata@4'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:363: undefined reference to `mysql_num_fields@4'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:370: undefined reference to `mysql_fetch_field@4'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:433: undefined reference to `mysql_free_result@4'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:439: undefined reference to `mysql_store_result@4'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:441: undefined reference to `mysql_free_result@4'
。。。。。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。。。
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:1486: undefined reference to `mysql_query@8'
debug/qsql_mysql.o:C:\Qt\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\mysql/../../../sql/drivers/mysql/qsql_mysql.cpp:1512: undefined reference to `mysql_real_escape_string@16'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: Leaving directory `C:/Qt/QtSDK/QtSources/4.8.1/src/plugins/sqldrivers/mysql'
mingw32-make.exe[1]: *** [debug\qsqlmysqld4.dll] Error 1
mingw32-make.exe: *** [debug] Error 2
00:02:59: 进程"C:\Qt\QtSDK\mingw\bin\mingw32-make.exe"退出,退出代码 2 。
构建项目mysql 时发生错误 (目标: 桌面)
当执行构建步骤 'Make'时
以上提示没有定义的参数,经查找,都是在 mysql/include 下的mysq.h 里定义的参数。
请问各位大神:本人的这个错误,是否mysql.h 在编译过程中没被编译进去呢?如果是,该如何解决啊?
如果不是mysql.h 的问题,可能的问题会是什么啊?谢谢各位了。
<a href="http://www.linezing.com"><img src="http://img.tongji.linezing.com/2490637/tongji.gif"/></a>
大神,我只是操作系统是64位的哦,SDK应该32位的吧。
第一贴最最后面那个关于myshql.h的问题麻烦给点建议哦,走投无路了啊。。
问题初步解决:
考虑了很久,决定把下载的mysql从5.5 降到大家都编译成功的5.1.
参照各位大神的文章,生成libmysql.a 后,从qtcreator中打开mysql.pro,,并将其内容改成如下内容后:
TARGET = qsqlmysql
INCLUDEPATH+=C:/MySQL/include
LIBS += -LC:/MySQL/lib/opt/ -llibmysql
SOURCES = main.cpp
include(../../../sql/drivers/mysql/qsql_mysql.pri)
include(../qsqldriverbase.pri)
分别编译 debug和release版本,成功!!!!!!!!!!!!!!!!!!
看来是mysql版本的问题,之前为这个搞了快8.9天了。。我的4个文件啊。。。
引用第4楼zshxie于2012-12-25 00:49发表的 :
问题初步解决:
考虑了很久,决定把下载的mysql从5.5 降到大家都编译成功的5.1.
参照各位大神的文章,生成libmysql.a 后,从qtcreator中打开mysql.pro,,并将其内容改成如下内容后:
TARGET = qsqlmysql
INCLUDEPATH+=C:/MySQL/include
.......
mysql 从5.5换成5.1 成功了?遇到和你同样的问题,难道要真的换MySQL 的版本啊
--转自