[SOLVED] problems with QT5.4 x64, mingw w64 an MySql 64bit on Win7
-
I am running a third-party sjlj build from http://www.tver-soft.org/qt64. and attempting to connect to Mysql server.
System environment: Windows 7, 64bit
-Qt5.4.1-x64
-Qt Creator 3.4
-mingw492-w64
-MySQL 64bit (tried 5.5, 5.6, 5.7) all with same result.
Initially used included qsqlmysql files from third-party build. While in Debug, it fails with SIGSEGV (Segmentation fault) while attempting to open the connection to the server.- QSqlDatabase::db
- db.Open
Then I build my own driver, everything builds great. While in debug, it fails again with SIGSEGV (Segmentation fault). But this time it fails inside qsql_mysql.cpp line 1265
if ((d->mysql = mysql_init((MYSQL*) 0)) && mysql_real_connect(d->mysql, host.isNull() ? static_cast<const char *>(0) : host.toLocal8Bit().constData(), user.isNull() ? static_cast<const char *>(0) : user.toLocal8Bit().constData(), password.isNull() ? static_cast<const char *>(0) : password.toLocal8Bit().constData(), db.isNull() ? static_cast<const char *>(0) : db.toLocal8Bit().constData(), (port > -1) ? port : 0, unixSocket.isNull() ? static_cast<const char *>(0) : unixSocket.toLocal8Bit().constData(), optionFlags)) { if (!db.isEmpty() && mysql_select_db(d->mysql, db.toLocal8Bit().constData())) { setLastError(qMakeError(tr("Unable to open database '%1'").arg(db), QSqlError::ConnectionError, d)); mysql_close(d->mysql); setOpenError(true); return false; } #if MYSQL_VERSION_ID >= 50000 if(reconnect) mysql_options(d->mysql, MYSQL_OPT_RECONNECT, &reconnect); #endif } else { setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d)); mysql_close(d->mysql); d->mysql = NULL; setOpenError(true); return false; }
I am not receiving the else notice of "Unable to connect"
I believe my driver is working, but am unsure where to look from here.
If we build on QT4.5 32bit, wingw32, things work fine. We can even run on a Mysql 64bit install using a libmysql.dll from a 32 bit mysql install. not a desired condition.
We have been fighting this for a few days now.
Thank you in advance for any help or direction.[edit: Added missing coding tags ```before and after SGaist]
-
@swankster
Solution was, finding this gem https://github.com/kivy/kivy/wiki/Creating-a-64-bit-development-environment-with-MinGW-on-Windows then making a few modifications. Basically rebuilding MySQL Connector.C 6.1\lib\libmysql.dll with gendef.exe
will need to Install Ruby x64, I used (rubyinstaller-2.2.2-x64.exe)
set Ruby...\bin to System Variables.
copy C:\Program Files\MySQL\MySQL Connector.C 6.1 to C: and rename as \mysql-connector
open cmd window
C:\mysql-connector\lib
> gendef.exe libmysql.dll
> dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib
> gem install mysql2 --no-rdoc --no-ri -- '--with-mysql-lib="C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include"'copy c:\mysql-connector\lib\libmysql.lib
to c:\Program Files\MySQL\MySQL Server 5.6\libcopy c:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\mysql2-0.3.18-x64-mingw32\vendor\libmysql.dll
to c:\Program Files\MySQL\MySQL Server 5.6\libNow build MySql Driver for QT. I used third party QT 64 from http://www.tver-soft.org/qt64
put in System Variables
C:\Qt\5.4.1-x64\mingw492r1-sjlj-rev1\qt-5.4.1-x64-mingw492r1-sjlj-rev1\bin;
C:\Qt\5.4.1-x64\mingw492r1-sjlj-rev1\mingw64\bin;
C:\Qt\5.4.1-x64\mingw492r1-sjlj-rev1\mingw64\lib
Create QT cmd window (needs custom qtenv.bat file, copied from other QT version and modified for x64)
from QT cmd x64set mysql=C:\PROGRA~1\MySQL\MYSQLS~1.6 (must be short names)
cd c:\Qt\qt-5.4.1-src\qtbase\src\plugins\sqldrivers\mysql
qmake "INCLUDEPATH+=%mysql%\include" "LIBS+=%mysql%\lib\libmysql.lib" -o Makefile mysql.pro
mingw32-makecopy qsqlmysql.dll and qsqlmysqld.dll from C:\Qt\qt-5.4.1-src\qtbase\plugins\sqldrivers to c:\Qt\5.4.1-x64\mingw492r1-sjlj-rev1\qt-5.4.1-x64-mingw492r1-sjlj-rev1\plugins\sqldrivers
copy %mysql%\lib\libmysql.dll c:\windows
Hope this helps someone else save a few days worth of time and aggravation.