Quazip-1.3 static linking issue
-
Hello!
I have built
Quazip-1.3
libs statically withzlib-win-build-1.2.12 (build-VS2019-MT) - libz-static.lib
. When I try to build my project then I get a lot of linking errors:LINK : warning LNK4217: symbol '?commit@QSaveFile@@QAE_NXZ (public: bool __thiscall QSaveFile::commit(void))' defined in 'Qt5Cored.lib(qsavefile.obj)' is imported by 'quazip1-qt5d.lib(qioapi.obj)' in function '"bool __cdecl quazip_close(class QIODevice *)" (?quazip_close@@YA_NPAVQIODevice@@@Z)' LINK : warning LNK4217: symbol '?staticMetaObject@QSaveFile@@2UQMetaObject@@B (public: static struct QMetaObject const QSaveFile::staticMetaObject)' defined in 'Qt5Cored.lib(qsavefile.obj)' is imported by 'quazip1-qt5d.lib(qioapi.obj)' in function '"class QSaveFile * __cdecl qobject_cast<class QSaveFile *>(class QObject *)" (??$qobject_cast@PAVQSaveFile@@@@YAPAVQSaveFile@@PAVQObject@@@Z)' quazip1-qt5d.lib(JlCompress.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QString & __thiscall QString::operator+=(char)" (__imp_??YQString@@QAEAAV0@D@Z) referenced in function "public: static class QStringList __cdecl JlCompress::extractDir(class QuaZip &,class QString const &)" (?extractDir@JlCompress@@SA?AVQStringList@@AAVQuaZip@@ABVQString@@@Z) Hint on symbols that are defined and could potentially match: "__declspec(dllimport) public: class QString & __thiscall QString::operator+=(class QString const &)" (__imp_??YQString@@QAEAAV0@ABV0@@Z) quazip1-qt5d.lib(quazipfileinfo.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QIODevice * __thiscall QDataStream::device(void)const " (__imp_?device@QDataStream@@QBEPAVQIODevice@@XZ) referenced in function "class QDateTime __cdecl getNTFSTime(class QByteArray const &,int,int *)" (?getNTFSTime@@YA?AVQDateTime@@ABVQByteArray@@HPAH@Z) debug\QuaZipTest.exe : fatal error LNK1120: 2 unresolved externals
Code:
QT -= gui CONFIG += c++latest console static CONFIG -= app_bundle # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp # Default rules for deployment. #qnx: target.path = /tmp/$${TARGET}/bin #else: unix:!android: target.path = /opt/$${TARGET}/bin #!isEmpty(target.path): INSTALLS += target MOC_DIR = ./resources/moc OBJECTS_DIR = ./resources/objects RCC_DIR = ./resources/resource DEFINES += QUAZIP_STATIC INCLUDEPATH += "C:/ZipDev/quazip-1.3/quazip" INCLUDEPATH += "C:/ZipDev/zlib-win-build-1.2.12" CONFIG(debug, debug|release) { DESTDIR = $$OUT_PWD/debug contains(QMAKE_TARGET.arch, x86_64) { LIBS += -L"C:/ZipDev/quazip-1.3/msvc2019/static/x64/debug/quazip/Debug" -lquazip1-qt5d LIBS += -L"C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/x64/Debug" -llibz-static } else { LIBS += -L"C:/ZipDev/quazip-1.3/msvc2019/static/x86/debug/quazip/Debug" -lquazip1-qt5d LIBS += -L"C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/Debug" -llibz-static } } else { DESTDIR = $$OUT_PWD/release contains(QMAKE_TARGET.arch, x86_64) { LIBS += -L"C:/ZipDev/quazip-1.3/msvc2019/static/x64/release/quazip/Release" -lquazip1-qt5 LIBS += -L"C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/x64/Release" -llibz-static } else { LIBS += -L"C:/ZipDev/quazip-1.3/msvc2019/static/x86/release/quazip/Release" -lquazip1-qt5 LIBS += -L"C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/Release" -llibz-static } } #QMAKE_POST_LINK = $$(QTDIR)/bin/windeployqt.exe $$shell_quote($$DESTDIR/$$shell_quote($$TARGET).exe) --no-compiler-runtime
main.cpp:
#include <QCoreApplication> #include <QTextStream> #include <QTextCodec> #include <Windows.h> #include "JlCompress.h" #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QTextStream output(stdout); output.setCodec(QTextCodec::codecForName("IBM 866")); output << "This is a Quazip test..." << endl; QString zipPath = "C:\\Users\\cobra\\Downloads\\22598.200_amd64_en-us_professional_7405f8e8_convert.zip"; QString downloadsFolder = "C:\\Users\\cobra\\Downloads\\22598.200_amd64_en-us_professional"; const QStringList extractedDir = JlCompress::extractDir(zipPath, downloadsFolder); if (!extractedDir.isEmpty()) { output << "Is empty(): " << "No" << endl; } else { output << "Is empty(): " << "Yes" << endl; } for (QString extractedFileName : extractedDir) { output << "Extracting: " << extractedFileName << endl; } system("Pause"); return 0; }
I have used these commands to build
QuaZip
statically:cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDebug" -DBUILD_SHARED_LIBS=OFF -S . -B C:/ZipDev/quazip-1.3/msvc2019/static/x86/debug -D QUAZIP_QT_MAJOR_VERSION=5 "-DCMAKE_PREFIX_PATH=C:/Qt/5.9.9/msvc2019" -DZLIB_INCLUDE_DIR="C:/ZipDev/zlib-win-build-1.2.12" -DZLIB_LIBRARY="C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/Debug/libz-static.lib" -G "Visual Studio 16 2019" -A "Win32" cmake --build C:/ZipDev/quazip-1.3/msvc2019/static/x86/debug --config Debug
Also, I have checked the
QuaZip
library -quazip1-qt5d.lib
usinglib /list
anddumpbin /directives
.C:\ZipDev\quazip-1.3\msvc2019\static\x86\debug\quazip\Debug>lib /list quazip1-qt5d.lib Microsoft (R) Library Manager Version 14.29.30143.0 Copyright (C) Microsoft Corporation. All rights reserved. QuaZip.dir\Debug\mocs_compilation_Debug.obj QuaZip.dir\Debug\unzip.obj QuaZip.dir\Debug\zip.obj QuaZip.dir\Debug\JlCompress.obj QuaZip.dir\Debug\qioapi.obj QuaZip.dir\Debug\quaadler32.obj QuaZip.dir\Debug\quachecksum32.obj QuaZip.dir\Debug\quacrc32.obj QuaZip.dir\Debug\quagzipfile.obj QuaZip.dir\Debug\quaziodevice.obj QuaZip.dir\Debug\quazip.obj QuaZip.dir\Debug\quazipdir.obj QuaZip.dir\Debug\quazipfile.obj QuaZip.dir\Debug\quazipfileinfo.obj QuaZip.dir\Debug\quazipnewinfo.obj C:\ZipDev\quazip-1.3\msvc2019\static\x86\debug\quazip\Debug> C:\ZipDev\quazip-1.3\msvc2019\static\x86\debug\quazip\Debug>dumpbin /directives quazip1-qt5d.lib Microsoft (R) COFF/PE Dumper Version 14.29.30143.0 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file quazip1-qt5d.lib File Type: LIBRARY Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Linker Directives ----------------- /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug /DEFAULTLIB:libcpmtd /DEFAULTLIB:LIBCMTD /DEFAULTLIB:OLDNAMES Summary 28 .CRT$XCU 6C .bss 3150 .chks64 6E .data 1B8 .data$rs CA550 .debug$S 654 .debug$T CD1 .drectve 6A85 .rdata 46A .rdata$r 3C .rtc$IMZ 3C .rtc$TMZ 2B8 .sxdata 12C .text$di 2A606 .text$mn 2CD6 .text$x 67C .voltbl 2FA4 .xdata$x C:\ZipDev\quazip-1.3\msvc2019\static\x86\debug\quazip\Debug>
The issue only occurs with
Quazip
static libs, dynamic libs are working well. What could cause such errors with static libs? Thank you. -
Seems like you forgot to install QuaZip...
add
-DCMAKE_INSTALL_PREFIX="C:/ZipDev/QuaZip"
to the first cmake call (the configuration) and, after the build, callcmake --build C:/ZipDev/quazip-1.3/msvc2019/static/x86/debug --config Debug --target install
. You will now have the Quazip library installed inC:/ZipDev/QuaZip
that you can reference in your .pro file -
I have tried your solution but it still leads to these linking errors.
.pro file:
QT -= gui CONFIG += c++latest console static CONFIG -= app_bundle # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp # Default rules for deployment. #qnx: target.path = /tmp/$${TARGET}/bin #else: unix:!android: target.path = /opt/$${TARGET}/bin #!isEmpty(target.path): INSTALLS += target MOC_DIR = ./resources/moc OBJECTS_DIR = ./resources/objects RCC_DIR = ./resources/resource DEFINES += QUAZIP_STATIC INCLUDEPATH += "C:/ZipDev/QuaZip/include/QuaZip-Qt5-1.3/quazip" INCLUDEPATH += "C:/ZipDev/zlib-win-build-1.2.12" CONFIG(debug, debug|release) { DESTDIR = $$OUT_PWD/debug LIBS += -L"C:/ZipDev/QuaZip/lib" -lquazip1-qt5d LIBS += -L"C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/Debug" -llibz-static } #QMAKE_POST_LINK = $$(QTDIR)/bin/windeployqt.exe $$shell_quote($$DESTDIR/$$shell_quote($$TARGET).exe) --no-compiler-runtime
Full error log: https://pastebin.com/raw/GL0tK7xV
-
@Cobra91151 said in Quazip-1.3 static linking issue:
The content of C:/ZipDev/QuaZip folder:
Looks good.
#include "JlCompress.h"
Did you try to unpack QuaZip directly in your source code? Do you have another instance of
JlCompress.h
in your source tree? If so delete it and also change it to#include <JlCompress.h>
just in case -
No, my project source code is available:
C:\Users\cobra\Documents\Projects\CPP\QuaZipTest
QuaZip
is installed:C:\ZipDev\QuaZip
I have only 1 instance ofJlCompress
in the source tree, please check out the following screenshot:I changed to
<JlCompress.h>
but it still displays these errors. -
I have tried to unpack
QuaZip
directly to the source code:.pro file: QT -= gui CONFIG += c++latest console static CONFIG -= app_bundle # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp # Default rules for deployment. #qnx: target.path = /tmp/$${TARGET}/bin #else: unix:!android: target.path = /opt/$${TARGET}/bin #!isEmpty(target.path): INSTALLS += target MOC_DIR = ./resources/moc OBJECTS_DIR = ./resources/objects RCC_DIR = ./resources/resource DEFINES += QUAZIP_STATIC #INCLUDEPATH += "C:/ZipDev/QuaZip/include/QuaZip-Qt5-1.3/quazip" #INCLUDEPATH += "C:/ZipDev/zlib-win-build-1.2.12" CONFIG(debug, debug|release) { DESTDIR = $$OUT_PWD/debug LIBS += -L"C:/Users/cobra/Documents/Projects/CPP/QuaZipTest" -lquazip1-qt5d LIBS += -L"C:/ZipDev/zlib-win-build-1.2.12/build-VS2019-MT/Debug" -llibz-static } #QMAKE_POST_LINK = $$(QTDIR)/bin/windeployqt.exe $$shell_quote($$DESTDIR/$$shell_quote($$TARGET).exe) --no-compiler-runtime HEADERS += \ JlCompress.h \ ioapi.h \ minizip_crypt.h \ quaadler32.h \ quachecksum32.h \ quacrc32.h \ quagzipfile.h \ quaziodevice.h \ quazip.h \ quazip_global.h \ quazip_qt_compat.h \ quazipdir.h \ quazipfile.h \ quazipfileinfo.h \ quazipnewinfo.h \ unzip.h \ zconf.h \ zip.h \ zlib.h
The same issues are still exists. Compilation log: https://pastebin.com/raw/sPKErHen
-
I have an idea. When selecting
cmake
compiler:-G "Visual Studio 16 2019" -A "Win32"
It produces the following output:
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19044. -- The C compiler identification is MSVC 19.29.30143.0 -- The CXX compiler identification is MSVC 19.29.30143.0
So, I will try to build it using VS 2022:
-G "Visual Studio 17 2022" -A "Win32"
to check for such issues. -
@Cobra91151 said in Quazip-1.3 static linking issue:
I have tried to unpack QuaZip directly to the source code:
No, that's a mess, please revert.
When selecting cmake compiler: -G "Visual Studio 16 2019" -A "Win32"
I wouldn't bother, just use
-G"NMake Makefiles"
, it's a bit slower but QuaZip is not a big project and that will automatically select the compiler you are using and you won't even need to specify--config Debug
.In any case, this does not seem like a problem in the QuaZip build side. The library is installed correctly so that side worked, the problem is in your program using it. Can you try with a brand new project?
-
I know, it is the mess. That's why I always linking instead of unpacking everything to the source. Actually, this is the brand new project which I have created to test
Quazip
because in my real project it leads to the same issues. Previously, I have used thequazip-0.9.1
and it worked without issue. This issue is only withQuazip-1.3
. I do not think it is related to the program. I think, something is wrong withQuazip
static library. Anyway, I will try my and your solution:-G"NMake Makefiles"
and reply soon. -
I have tried both solutions with
VS 2022
andNMake Makefiles
, but it still displays these linking errors. So, I have found this old article: https://forum.qt.io/topic/8492/solved-cannot-get-quazip-test-to-work/2, it maked as solved but I can not find the actual post with a solution. Any ideas? -
QuaZip
VS solution uses by default:Use Multi-Byte Character Set
and it could be changed to:Use Unicode Character Set
orNot Set
.
When I try to add my test project usingVS 2019
->Qt extension
, it displays the charset as:Not Set
.
So, I think it could beUse Unicode Character Set
or better to set theNot Set
option for thisQuaZip
static library when buildingQuaZip
lib. -
@Cobra91151 said in Quazip-1.3 static linking issue:
drop QuaZip and create my own library
That's a giant leap.
- try compilying it dinamically and use it as a dll, why not
- consider alternatives, like KArchive
-
Using DLL is not an option in my case because it must be only
.exe
file for installer. I do not thinkKArchive
is worth trying since it could be the same issue at some point. I prefer code it by my own and have a full control over it. Simple lib to zip/unzip archives wrapper for Qt. Thanks. -
Hello!
I have created my own
CZip
library which adds content to archive and extracts it.
The issue is resolved.