PDA

View Full Version : QT MYSQL drive build, undefined reference to `mysql_get_client_version@0'



hehedaouziteng
31st December 2019, 19:45
Hi, I am struggling these for three days. I tried all I can do, and I believes this can be the last problem for me.

I am trying to build the QMYSQL drive, I followed Document (https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows)

There is no "Libs & Include Files" Module in mysql "Custom Install", so I select the folder from the sql serves.

I run the code on 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"

the result is :


Info: creating stash file C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\.qm ake.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.

it seems like does not detected mysql.

I check the the mysql log,


Command line: "MYSQL_INCDIR=C:/MySql/MySQL Server 8.0/include" "MYSQL_LIBDIR=C:/MySql/MySQL Server 8.0/lib"
Global lib dirs: [C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib] [C:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0 C:/Qt/Tools/mingw730_32/lib/gcc C:/Qt/Tools/mingw730_32/i686-w64-mingw32/lib C:/Qt/Tools/mingw730_32/lib]
Global inc dirs: [C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include] [C:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++ C:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/i686-w64-mingw32 C:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include/c++/backward C:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include C:/Qt/Tools/mingw730_32/lib/gcc/i686-w64-mingw32/7.3.0/include-fixed C:/Qt/Tools/mingw730_32/i686-w64-mingw32/include]
.......
looking for library mysql
.....
Trying source 5 (type inline) of library mysql ...
+ cd /d C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\con fig.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\con fig.tests\.qmake.stash
+ cd /d C:\Qt\5.12.6\Src\qtbase\src\plugins\sqldrivers\con fig.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

the problems seems like because of undefined reference to `mysql_get_client_version@0'

I checked the mysql/include. I am sure there is a "mysql.h" file, and a mysql_get_client_version function exisit, but it just a headfile, not even defined.

What should I do to build a MYSQL drive? thank you very much.

I also tried the method from the video https://www.youtube.com/watch?v=r1TbNjJSlX8&t=199s
it reported the error, library mysql is not definied.

Added after 26 minutes:

I solved It. The lib and include file should be comes from the MySQL Connector C 6.1.

this doc is better then old one.

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

ChrisW67
31st December 2019, 23:17
The placement of double-quotes in the qmake command line from the original docs was likely to cause you problems even if you had the correct libraries in place.