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

Create static lib and connect to Qt application



  • Hello, I am trying to create a static lib, the creation process passes, and in the end i have a JsonAPI.a file, which I want to connect to my application, but when I connect it and compile, the compiler gives me an error: Error running application ( 0xc0000142).
    Whan can cause such bizzare issue? Thank you in advance.
    MyProject.pro file:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2019-04-24T02:54:27
    #
    #-------------------------------------------------
    
    QT       += network
    
    QT       -= gui
    
    TARGET = JsonAPI
    TEMPLATE = lib
    CONFIG += staticlib
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use 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 += \
        httprequest.cpp \
        jsonserverapi.cpp
    
    HEADERS += \
        jsonserverapi.h \
        httprequest.h
    unix {
        target.path = /usr/lib
        INSTALLS += target
    }
    

    In the httprequest.h I am also including some of the Qt headers, my thoughts is that they may not be included into the lib file

    #include <QtNetwork/QNetworkAccessManager>
    #include <QString>
    #include <QObject>
    #include <QByteArray>
    #include <QtNetwork/QNetworkReply>
    #include <QtNetwork/QNetworkRequest>
    #include <QEventLoop>
    

  • Qt Champions 2019

    @mandruk1331 How do you add the static lib to your app?
    Please show the pro file.



  • @jsulm this is the .pro file of the project to which I am connecting the lib file:

    QT -= gui
    QT       += network
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    # 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). Please consult the documentation of the
    # deprecated API in order 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
    INCLUDEPATH += "C:/Users/<Username>/Documents/JsonAPI"
    LIBS += "C:/Users/<Username>/Documents/build-JsonAPI-Desktop_Qt_5_12_2_MinGW_32_bit-Release/release/libJsonAPI.a"
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        ../JsonAPI/jsonserverapi.h
    

    I have also set the dependencies form the main project to this lib


  • Qt Champions 2019

    @mandruk1331 said in Create static lib and connect to Qt application:

    connecting the lib file

    static libs are not "connected", they become part of your executable (at least the parts used by your app).
    Do you build your app in debug or release mode?
    Does your app build without any warnings/errors?
    Also, you activate C++11 in your app, but not in the lib.



  • @jsulm Both have been built in release mode using MinGW 32-bit

    This is the error which the main program gives: :-1:error: [Makefile.Release:65: release/MainProject.exe] Error -1073741502


  • Qt Champions 2019

    @mandruk1331 Is there something before that error?
    Did you try to do a clean rebuild: delete build directory, run qmake and build?



  • @jsulm
    This is what the console shows:

    E:/Work/Qt/Tools/mingw730_32/bin/mingw32-make -f Makefile.Release
    mingw32-make[1]: Entering directory 'C:/Users/<UserName>/Documents/build-MainProgram-Desktop_Qt_5_12_2_MinGW_32_bit-Release'
    g++ -Wl,-s -Wl,-subsystem,console -mthreads -o release/MainProgram.exe release/main.o  "C:/Users/Mr. User/Documents/build-JsonAPI-Desktop_Qt_5_12_2_MinGW_32_bit-Release/release/libJsonAPI.a" -LE:/Work/Qt/5.12.2/mingw73_32/lib E:/Work/Qt/5.12.2/mingw73_32/lib/libQt5Network.a E:/Work/Qt/5.12.2/mingw73_32/lib/libQt5Core.a   
    mingw32-make[1]: *** [Makefile.Release:65: release/MainProject.exe] Error -1073741502
    mingw32-make[1]: Leaving directory 'C:/Users/<UserName>/Documents/build-MainProject-Desktop_Qt_5_12_2_MinGW_32_bit-Release'
    mingw32-make: *** [Makefile:38: release] Error 2
    14:32:01: Process «E:\Work\Qt\Tools\mingw730_32\bin\mingw32-make.exe» exit code 2.
    

    Yes, I have tried doing that
    and in the end of compilation I am getting this error:
    Application was Unable to Start correctly 0xC0000142


  • Qt Champions 2019

    @mandruk1331 Does your user name really contain a space?
    You should try to put your project into a directory without spaces.



  • @jsulm I was able to resolve the issue, it was due to incorrect compiler installation I re-intalled and now everything is working.
    But now I have another issue the compiler gives me next issue:

    error: undefined reference to `_imp___ZN21QNetworkAccessManagerD1Ev'
    httprequest.cpp:-1: error: undefined reference to `_imp___ZN15QNetworkRequestC1ERK4QUrl'
    httprequest.cpp:-1: error: undefined reference to `_imp___ZNK13QNetworkReply9attributeEN15QNetworkRequest9AttributeE'
    

    How could I add the source files to be also included in the lib file? Thank you in advance


  • Lifetime Qt Champion

    Hi,

    When compiling the library or the application ?


Log in to reply