Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Adding and deploying static *.a library. How?



  • Hello all!

    I have static library libzip.a. How to add and deploy it in Qt project and start to use it?
    When I am trying to compile I have this error:

    Undefined symbols for architecture x86_64:
      "_crc32", referenced from:
          __zip_string_crc32 in libzipstatic.a(zip_string.c.o)
         (maybe you meant: _z_crc32_combine64, _z_crc32_combine , _z_crc32_z , _z_crc32 , __zip_string_crc32 )
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    ** BUILD FAILED **
    
    
    The following build commands failed:
    	Ld Debug-iphonesimulator/plainc_libzip.app/plainc_libzip normal x86_64
    (1 failure)
    make: *** [xcodebuild-debug-simulator] Error 65
    12:29:10: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project plainc_libzip (kit: Qt 5.12.1 for iOS Simulator)
    When executing step "Make"
    

    I have:


    In *.pro

    QT += quick
    CONFIG += c++11
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Refer to the documentation for the
    # deprecated API to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        libs/libzip/config.h \
        libs/libzip/zip.h \
        libs/libzip/zipconf.h
    
    macx: LIBS += -L$$PWD/libs/libzip/ -lzipstatic
    
    INCLUDEPATH += $$PWD/libs/libzip
    DEPENDPATH += $$PWD/libs/libzip
    
    macx: PRE_TARGETDEPS += $$PWD/libs/libzip/libzipstatic.a
    
    
    ios: LIBS += -L$$PWD/libs/libzip/ -lzipstatic
    
    INCLUDEPATH += $$PWD/libs/libzip
    DEPENDPATH += $$PWD/libs/libzip
    
    ios: PRE_TARGETDEPS += $$PWD/libs/libzip/libzipstatic.a
    

    In main.cpp

    // System includes
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include "libs/libzip/zip.h"
    
    
    // Application includes
    
    // Constants
    const QString Main = "qrc:/main.qml";
    
    
    // QtQuick Application
    int main(int Counter, char *Arguments[]) {
    
    	const char *vZipPath = "/libzip/test.zip";
    	zip_t *vZip = zip_open(vZipPath,ZIP_CREATE,nullptr);
    
    	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    	QGuiApplication Application(Counter, Arguments);
    
    	QQmlApplicationEngine Engine;
    	Engine.load(QUrl(Main));
    	if (Engine.rootObjects().isEmpty())
    		return -1;
    
    	return Application.exec();
    }
    

  • Lifetime Qt Champion

    Hi,

    If it's a static library you don't need to deploy it.

    From the looks of the error you likely have a 32 bit build while you are building a 64 bit application.



  • @SGaist It has no any relation to the 32bit or 64bit application. This function from zlib and mean length of word for compressing.



  • Solution found for MacOS and iOS.
    It's might be working well for another platforms. I haven't tested it yet.

    Every library that is using by libzip should be added manually to the QT project and if it's not by default in the system you need to build it like static. If there zlib - then add it manually, if there SSL - then add it manually, etc

    The step-by-step guidance for building libzip published by me on Github

    There are couple of strange things that I found (I don't know the cause of it):

    • In the directory where located library appeared couple of symlinks on the real shared library file when I am attaching it to QT project via symlinks it's not working, only direct original file attaching to project working well (it's mean important for attaching zlib from system folder). See the screenshot

    0_1551431264962_Screen Shot 2019-03-01 at 12.04.58.png

    • The libzip library only working when you attaching it to QT Project like statical library (*.a), all of attempts of using like shared/dynamic libraray (*.dylib) have got failed, even it's installed like the operational system part.

    Code from that works for me *.pro file:

    macx {
    
    LIBS += -lz.1
    LIBS += -L$$PWD/libs/libzip/ -lzipstatic
    
    INCLUDEPATH += $$PWD/libs/libzip
    DEPENDPATH += $$PWD/libs/libzip
    
    PRE_TARGETDEPS += $$PWD/libs/libzip/libzipstatic.a
    
    }
    
    ios {
    
    LIBS += -lz.1
    LIBS += -L$$PWD/libs/libzip/ -lzipstatic
    
    INCLUDEPATH += $$PWD/libs/libzip
    DEPENDPATH += $$PWD/libs/libzip
    
    PRE_TARGETDEPS += $$PWD/libs/libzip/libzipstatic.a
    
    }
    

    SUPER-MEGA-HUGE (SMH) thanks to Thomas Klausner (one of authors of libzip). He has been helping me to solve this trouble.


Log in to reply