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/nGU9Lsz

    In .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?


  • Moderators

    @Kamba said:

    /usr/lib/libz.so.1:-1: error: error adding symbols: DSO missing from command line

    see this.
    This should also solve your first error.



  • 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_'
    

  • Moderators

    @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 windows

    win32 {
        LIBS += -L$$PWD/quazip -lzdll
    }
    

    W7 64bit, QT 5.6


  • Qt Champions 2016

    @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.

    @raven-worx

    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.


  • Qt Champions 2016

    @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


  • Qt Champions 2016

    @Kamba

    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:

    @Kamba

    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?


  • Qt Champions 2016

    @Kamba

    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 file

    INCLUDEPATH += $$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?


  • Qt Champions 2016

    @Kamba said:

    So I guess this is it?

    Indeed, this is it.
    Cheers!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.