Qt static with MySQL issue
-
Hi! I have built
Qt
statically withMySQL -sql-mysql
. Then I included library to the projectpro
file:LIBS += -L"C:/MySQL/mysql-5.7.22-win32/lib" -lmysqlclient
But it still requires
libmysql.dll
.Screenshot:
I use
mysqlclient
because info in theMySQL
docs states that this lib is static - http://ftp.nchu.edu.tw/MySQL/doc/refman/5.0/en/windows-client-compiling.htmlI also tried with
LIBS += -L"C:/MySQL/mysql-5.7.22-win32/lib" -llibmysql
but the same issue still exists. I want to have this library embedded into the executable. I have compiledQt 5.9.6
withmysql-5.7.22-win32
. Any ideas how to make it embedded? Thanks. -
Hi,
That's likely because you are linking to the dynamic version of
libqmysqlclient
.Check that you really have a static version of the MySQL client library.
-
Hi! You are right. I have updated the
MySQL
tomysql-5.7.23
and run a few tests, then commented the code:#LIBS += -L"C:/MySQL/mysql-5.7.23-win32/lib" -llibmysql #LIBS += -L"C:/MySQL/mysql-5.7.23-win32/lib" -lmysqlclient
I get the issue:
:-1: error: LNK1181: cannot open input file 'C:\MySQL\mysql-5.7.22-win32\lib\libmysql.lib'
This means that
Qt
uses the wrongMySQL
lib (shared
). It should usemysqlclient
(static
). So I need to reconfigure it with lib path to exactly point to theC:\MySQL\mysql-5.7.23-win32\lib\mysqlclient.lib
static library or remove all the libs from the directory except for themysqlclient.lib
? Thanks. -
Are you sure
C:\MySQL\mysql-5.7.23-win32\lib\mysqlclient.lib
is a static library ? The.lib
files can either be static libraries or import libraries. -
Yes, I know, it could be static/shared library. I don't know 100% this library is static. But from
MySQL
docs:2.16.7. Compiling MySQL Clients on Windows ... You can either link your code with the dynamic libmysql.lib library, which is just a wrapper to load in libmysql.dll on demand, or link with the static mysqlclient.lib library. The MySQL client libraries are compiled as threaded libraries, so you should also compile your code to be multi-threaded.
It should be static. I will check it with
Visual Studio 2017
staticMFC
test project. -
Are you looking at the latest version of the documentation ?
-
So, you are right! I have checked the
mysqlclient.lib
usingVS 2017
staticMFC
test project and I get the issues:It means this library is a
dynamic
. So where to get the static library or source files to build this library as static? Thanks. -
MT and MD are just related to the Windows runtime type you'll be using.
-
I have checked it using
lib /list mysqlclient.lib
and7zip
, it displayed:This means the library is 100% static. So how to add it to
Qt
during reconfiguration? Should I provide full path to the library or remove all libs exceptmysqlclient.lib
and provide path? Thanks. -
Can you show which configuration options you used ?
-
Ok, my batch file:
SET /P qtBuildType=Qt build type (shared/static): SET /P qtBuildMySqlIncludePath=MySql include path: SET /P qtBuildMySqlLibPath=MySql lib path: SET /P qtBuildOpenSSLIncludePath=OpenSSL include path: SET /P qtBuildOpenSSLLibPath=OpenSSL lib path: SET /P qtBuildPath=Enter Qt build path: configure.bat -debug-and-release -%qtBuildType% -opensource -nomake tools -nomake examples -no-ltcg -sql-mysql -I "%qtBuildMySqlIncludePath%" -L "%qtBuildMySqlLibPath%" -ssl -openssl -openssl-linked -I "%qtBuildOpenSSLIncludePath%" -L "%qtBuildOpenSSLLibPath%" OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32" OPENSSL_LIBS_DEBUG="-lssleay32MTd -llibeay32MTd" OPENSSL_LIBS_RELEASE="-lssleay32MT -llibeay32MT" -prefix "%qtBuildPath%"
For example,
MySql
include path was :C:\MySQL\mysql-5.7.22-win32\include
andMySql
lib pathC:\MySQL\mysql-5.7.22-win32\lib
but it makeQt
to useC:\MySQL\mysql-5.7.22-win32\lib\libmysql.lib
(dynamic). I think, should be another way to set proper library. -
I would add
MYSQL_LIBS=-lmysqlclient
. -
I added the
MYSQL_LIBS="-lmysqlclient"
to configure:configure.bat -debug-and-release -%qtBuildType% -opensource -nomake tools -nomake examples -no-ltcg -sql-mysql -I "%qtBuildMySqlIncludePath%" -L "%qtBuildMySqlLibPath%" MYSQL_LIBS="-lmysqlclient" -ssl -openssl -openssl-linked -I "%qtBuildOpenSSLIncludePath%" -L "%qtBuildOpenSSLLibPath%" OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32" OPENSSL_LIBS_DEBUG="-lssleay32MTd -llibeay32MTd" OPENSSL_LIBS_RELEASE="-lssleay32MT -llibeay32MT" -prefix "%qtBuildPath%"
But I get the issue:
I think I should also provide the
libmysql
toMYSQL_LIBS
or the problem is withmysql-5.7.23
. -
I have found the issue! Adding this line
MYSQL_LIBS="-lmysqlclient"
to configure for some reason breaks the detection ofMySQL
. I will try again to confirm it. -
Yes, I was right. Adding
MYSQL_LIBS="-lmysqlclient"
breaks the detection ofMySQL
- 100% confirmed. -
I run a few tests and found that
Qt
requireslibmysql.lib
to configure, but since itdynamic
lib it won't work in my case. I think I should try to renamemysqlclient.lib
tolibmysql.lib
and test it. -
No, it fails with detection the
MySQL
iflibmysql.lib
has been changed, renamed or removed. -
I think I have found the issue.
This line of code in the file -
configure.json
-{ "libs": "-lmysqlclient", "condition": "!config.win32" }
disablesmysqlclient
(static) lib because condition states that!win32
, means notWindows
system. I will change it and try again. -
I have tried different solutions but it all failed.
The config.log:
+ cd /d D:\QtBuild\Src\config.tests\mysql && D:\QtBuild\Src\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" "QMAKE_LIBDIR += C:\\MySQL\\mysql-5.7.23-win32\\lib C:\\OpenSSL\\openssl-1.0.2l-vs2017\\lib" "INCLUDEPATH += C:\\MySQL\\mysql-5.7.23-win32\\include C:\\OpenSSL\\openssl-1.0.2l-vs2017\\include" "LIBS += -lmysqlclient" D:/QtBuild/Src/config.tests/mysql + cd /d D:\QtBuild\Src\config.tests\mysql && set MAKEFLAGS=& nmake > Microsoft (R) Program Maintenance Utility Version 14.15.26726.0 > Copyright (C) Microsoft Corporation. All rights reserved. > cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdmysql.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\MySQL\mysql-5.7.23-win32\include -IC:\OpenSSL\openssl-1.0.2l-vs2017\include -ID:\QtBuild\Src\qtbase\mkspecs\win32-msvc -Fo @C:\Users\cobra\AppData\Local\Temp\nmC064.tmp > main.cpp > link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:mysql.exe @C:\Users\cobra\AppData\Local\Temp\nmC2B7.tmp > LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library > mysqlclient.lib(xml.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(libmysql.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(my_time.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(client.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(ctype.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function _win32_have_tcpip > mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegEnumValueA@32 referenced in function _win_init_registry > mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function _win32_have_tcpip > mysqlclient.lib(my_default.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_init.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_winfile.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_mess.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_mess.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _my_message_stderr > mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp__fprintf > mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp__fprintf > mysqlclient.lib(client_authentication.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) referenced in function "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::_System_error_category::message(int)const " (?message@_System_error_category@std@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@H@Z) > mysqlclient.lib(sha2_password_common.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) > mysqlclient.lib(my_default.obj) : error LNK2019: unresolved external symbol __imp__printf referenced in function _my_load_defaults > mysqlclient.lib(ssl.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _ya_SSL_ASN1_TIME_to_string > mysqlclient.lib(log_client.obj) : error LNK2019: unresolved external symbol __imp__vfprintf referenced in function "void __cdecl error_log_vprint(enum error_log_level::type,char const *,char *)" (?error_log_vprint@@YAXW4type@error_log_level@@PBDPAD@Z) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__EqualSid@8 referenced in function "public: bool __thiscall Sid::operator==(class Sid const &)" (??8Sid@@QAE_NABV0@@Z) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__GetTokenInformation@20 referenced in function "public: __thiscall Sid::Sid(void *)" (??0Sid@@QAE@PAX@Z) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__IsValidSid@4 referenced in function "public: bool __thiscall Sid::is_valid(void)const " (?is_valid@Sid@@QBE_NXZ) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__LookupAccountNameW@28 referenced in function "public: __thiscall Sid::Sid(wchar_t const *)" (??0Sid@@QAE@PB_W@Z) > mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextA@20 referenced in function "public: __thiscall TaoCrypt::OS_Seed::OS_Seed(void)" (??0OS_Seed@TaoCrypt@@QAE@XZ) > mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: __thiscall TaoCrypt::OS_Seed::~OS_Seed(void)" (??1OS_Seed@TaoCrypt@@QAE@XZ) > mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: void __thiscall TaoCrypt::OS_Seed::GenerateSeed(unsigned char *,unsigned int)" (?GenerateSeed@OS_Seed@TaoCrypt@@QAEXPAEI@Z) > mysql.exe : fatal error LNK1120: 17 unresolved externals > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\link.EXE"' : return code '0x460' > Stop. => source failed verification. Trying source 6 (type inline) of library mysql ... + cd /d D:\QtBuild\Src\config.tests\mysql && D:\QtBuild\Src\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" "QMAKE_LIBDIR += C:\\MySQL\\mysql-5.7.23-win32\\lib C:\\OpenSSL\\openssl-1.0.2l-vs2017\\lib" "INCLUDEPATH += C:\\MySQL\\mysql-5.7.23-win32\\include C:\\OpenSSL\\openssl-1.0.2l-vs2017\\include" "LIBS += -lmysqlclient" D:/QtBuild/Src/config.tests/mysql + cd /d D:\QtBuild\Src\config.tests\mysql && set MAKEFLAGS=& nmake clean && set MAKEFLAGS=& nmake > Microsoft (R) Program Maintenance Utility Version 14.15.26726.0 > Copyright (C) Microsoft Corporation. All rights reserved. > del main.obj > del mysql.vc.pdb mysql.ilk mysql.idb > Microsoft (R) Program Maintenance Utility Version 14.15.26726.0 > Copyright (C) Microsoft Corporation. All rights reserved. > cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdmysql.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\MySQL\mysql-5.7.23-win32\include -IC:\OpenSSL\openssl-1.0.2l-vs2017\include -ID:\QtBuild\Src\qtbase\mkspecs\win32-msvc -Fo @C:\Users\cobra\AppData\Local\Temp\nmC3CF.tmp > main.cpp > link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:mysql.exe @C:\Users\cobra\AppData\Local\Temp\nmC632.tmp > LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library > mysqlclient.lib(xml.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(libmysql.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(my_time.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(client.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(ctype.obj) : error LNK2001: unresolved external symbol __imp__sprintf > mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function _win32_have_tcpip > mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegEnumValueA@32 referenced in function _win_init_registry > mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function _win32_have_tcpip > mysqlclient.lib(my_default.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_init.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_winfile.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_mess.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp____iob_func > mysqlclient.lib(my_mess.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _my_message_stderr > mysqlclient.lib(typelib.obj) : error LNK2001: unresolved external symbol __imp__fprintf > mysqlclient.lib(log_client.obj) : error LNK2001: unresolved external symbol __imp__fprintf > mysqlclient.lib(client_authentication.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) referenced in function "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::_System_error_category::message(int)const " (?message@_System_error_category@std@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@H@Z) > mysqlclient.lib(sha2_password_common.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) > mysqlclient.lib(my_default.obj) : error LNK2019: unresolved external symbol __imp__printf referenced in function _my_load_defaults > mysqlclient.lib(ssl.obj) : error LNK2019: unresolved external symbol __imp___snprintf referenced in function _ya_SSL_ASN1_TIME_to_string > mysqlclient.lib(log_client.obj) : error LNK2019: unresolved external symbol __imp__vfprintf referenced in function "void __cdecl error_log_vprint(enum error_log_level::type,char const *,char *)" (?error_log_vprint@@YAXW4type@error_log_level@@PBDPAD@Z) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__EqualSid@8 referenced in function "public: bool __thiscall Sid::operator==(class Sid const &)" (??8Sid@@QAE_NABV0@@Z) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__GetTokenInformation@20 referenced in function "public: __thiscall Sid::Sid(void *)" (??0Sid@@QAE@PAX@Z) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__IsValidSid@4 referenced in function "public: bool __thiscall Sid::is_valid(void)const " (?is_valid@Sid@@QBE_NXZ) > mysqlclient.lib(common.obj) : error LNK2019: unresolved external symbol __imp__LookupAccountNameW@28 referenced in function "public: __thiscall Sid::Sid(wchar_t const *)" (??0Sid@@QAE@PB_W@Z) > mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextA@20 referenced in function "public: __thiscall TaoCrypt::OS_Seed::OS_Seed(void)" (??0OS_Seed@TaoCrypt@@QAE@XZ) > mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: __thiscall TaoCrypt::OS_Seed::~OS_Seed(void)" (??1OS_Seed@TaoCrypt@@QAE@XZ) > mysqlclient.lib(random.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: void __thiscall TaoCrypt::OS_Seed::GenerateSeed(unsigned char *,unsigned int)" (?GenerateSeed@OS_Seed@TaoCrypt@@QAEXPAEI@Z) > mysql.exe : fatal error LNK1120: 17 unresolved externals > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\link.EXE"' : return code '0x460' > Stop. => source failed verification. test config.sqldrivers.libraries.mysql FAILED looking for library oci Trying source 0 (type inline) of library oci ... + cd /d D:\QtBuild\Src\config.tests\oci && D:\QtBuild\Src\qtbase\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" "QMAKE_LIBDIR += C:\\MySQL\\mysql-5.7.23-win32\\lib C:\\OpenSSL\\openssl-1.0.2l-vs2017\\lib" "INCLUDEPATH += C:\\MySQL\\mysql-5.7.23-win32\\include C:\\OpenSSL\\openssl-1.0.2l-vs2017\\include" "LIBS += -loci" D:/QtBuild/Src/config.tests/oci + cd /d D:\QtBuild\Src\config.tests\oci && set MAKEFLAGS=& nmake > Microsoft (R) Program Maintenance Utility Version 14.15.26726.0 > Copyright (C) Microsoft Corporation. All rights reserved. > cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -W0 -EHsc /Fdoci.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\MySQL\mysql-5.7.23-win32\include -IC:\OpenSSL\openssl-1.0.2l-vs2017\include -ID:\QtBuild\Src\qtbase\mkspecs\win32-msvc -Fo @C:\Users\cobra\AppData\Local\Temp\nmC6EC.tmp > main.cpp > .\main.cpp(2): fatal error C1083: Cannot open include file: 'oci.h': No such file or directory > NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\cl.EXE"' : return code '0x2' > Stop.
Any ideas how to make it compile with the
static
library? Thanks.