Solved Problems with QuaZip
-
Hey, I'm making program where I need to unzip a .zip file. I found that QuaZip is library for it and it's crossplatform(I need it for windows and linux). I'm working on linux machine, but code should also compile on windows machine.
The problem is that I don't know how to set it up. If I understood it right, QuaZip depends on Zlib and it needs zconf.h and zlib.h files from Zlib to work.
So I made quazip folder in my project folder which contains these files:
http://imgur.com/nGU9LszIn .pro file i added following lines:
HEADERS += $$PWD/quazip/*.h SOURCES += $$PWD/quazip/*.cpp SOURCES += $$PWD/quazip/*.c
I have included JlCompress.h like this in file where i need it:
#include "quazip/JlCompress.h"
and tried to use it like this:
JlCompress *asd; asd->extractDir(filepath, destinationDir);
but I get these errors:
:-1: error: quaziodevice.o: undefined reference to symbol 'deflate' /usr/lib/libz.so.1:-1: error: error adding symbols: DSO missing from command line :-1: error: collect2: error: ld returned 1 exit status
Could you help me please?
-
-
I added
unix { LIBS += -L$$PWD/quazip -lz }
to .pro file and now it compiles, but I guess it works because I have Zlib package installed on my machine. Installed Zlib package from repository shouldn't be a problem.
What should I write for windows in:win32 { }
I guess I need to add zlib1.dll, zdll.lib and zlib.def to quazip folder, so program can find Zlib?
I tried to add them there and wrote in .pro file:win32 { LIBS += -L$$PWD/quazip -lzdll }
but now I get a lot of warnings like
QString, QString)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes] bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) { ^
and errors like
error: undefined reference to `_imp___ZN10JlCompress10extractDirE7QStringS0_'
-
@Kamba
did you compile zlib on windows yourself?
AFAIK this should be a C library. So i dont see why you should get dllimport related errors? -
Files (zdll.lib, zlib.def and zlib1.dll) are from pre compiled dll package from Zlib's website.
Atm quazip folder looks like this http://imgur.com/nkFeqSc
And .pro file has this for windowswin32 { LIBS += -L$$PWD/quazip -lzdll }
W7 64bit, QT 5.6
-
@Kamba
What compiler was used to compile that library and what compiler are you using?QString, QString)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes] bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) { ^
This looks like a problem @koahnig was recently tackling, see here. The cause finally was discovered to be sources sneaking into the application code from the library.
error: undefined reference to `_imp___ZN10JlCompress10extractDirE7QStringS0_'
That's the linker complaining that your symbol can't be found.
AFAIK this should be a C library. So i dont see why you should get dllimport related errors?
C libraries export symbols exactly the same way as C++ libraries do. The only difference is that C++ symbol names are decorated.
Kind regards.
-
@kshegunov said:
@Kamba
What compiler was used to compile that library and what compiler are you using?QString, QString)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes] bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) { ^
This problem occurs on windows with MinGW 32bit.
-
@Kamba
This was a question consisting of two parts, and you answered only half of it. Is the library you're trying to link against compiled with 32bit MinGW?
Forget that, it's irrelevant as zlib is a C library.HEADERS += $PWD/quazip/*.h SOURCES += $PWD/quazip/*.cpp SOURCES += $PWD/quazip/*.c
So instead of building quazip as a library as it was intended, you're just inserting source. It's not going to work like that. Build quazip separately, and then link it to your project.
-
@kshegunov
Zlib? I don't know what compiler Zlib devs were using when they compiled it. I downloaded compiled dlls.
http://zlib.net/zlib128-dll.zip
I could try to compile it by myself from this
http://zlib.net/zlib128.zip -
Zlib? I don't know what compiler Zlib devs were using when they compiled it. I downloaded compiled dlls.
Yes, and it doesn't matter. It's my bad, sorry and we cross posted.
You should follow the instructions for building the library given on quazip's site, though. -
@kshegunov said:
Zlib? I don't know what compiler Zlib devs were using when they compiled it. I downloaded compiled dlls.
Yes, and it doesn't matter. It's my bad, sorry and we cross posted.
You should follow the instructions for building the library given on quazip's site, though.But how it is working on linux then if the problem is in quazip?
I'm going to try building quazip on windows. Should I also do same for linux? Then I don't need to include sources in the project right? -
But how it is working on linux then if the problem is in quazip?
On Linux
Q_DECL_EXPORT
expands to nothing, because there, the symbols are exported by default. On Windows it expands to__declspec(...)
depending on whether it's import or export. The compiler and/or linker doesn't like this declaration specifier to be repeated and will not handle conflicts involving it very gracefully.Basically, when you include the headers from the library you're telling the linker to import the symbol. But that symbol is nowhere to be found (as you don't have the quazip library at all) and the linker is confused ... it doesn't know where to get it, so you get the undefined references error.
I'm going to try building quazip on windows. Should I also do same for linux? Then I don't need to include sources in the project right?
Yes, you do the same for linux.
Yes, you don't include sources in the project.Kind regards.
-
Now I got it working. Built QuaZip on windows and linux.
added to .pro fileINCLUDEPATH += $$PWD/quazip LIBS += -L$$PWD/libs/ -lz LIBS += -L$$PWD/libs/ -lquazip
In quazip folder I have headers of Quazip. In libs folder I have .a files for windows and .so files for linux.
Including quazip for extracting works.#include "quazip/JlCompress.h"
This setup is working on both platforms. So I guess this is it?
-