Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create static lib and connect to Qt application

Create static lib and connect to Qt application

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 656 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by
    #1

    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>
    

    Mandruk1331

    jsulmJ 1 Reply Last reply
    0
    • mandruk1331M mandruk1331

      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>
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      mandruk1331M 1 Reply Last reply
      0
      • jsulmJ jsulm

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

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on last edited by
        #3

        @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

        Mandruk1331

        jsulmJ 1 Reply Last reply
        0
        • mandruk1331M mandruk1331

          @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

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          mandruk1331M 1 Reply Last reply
          1
          • jsulmJ jsulm

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

            mandruk1331M Offline
            mandruk1331M Offline
            mandruk1331
            wrote on last edited by
            #5

            @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

            Mandruk1331

            jsulmJ 1 Reply Last reply
            0
            • mandruk1331M mandruk1331

              @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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              mandruk1331M 1 Reply Last reply
              0
              • jsulmJ jsulm

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

                mandruk1331M Offline
                mandruk1331M Offline
                mandruk1331
                wrote on last edited by
                #7

                @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

                Mandruk1331

                jsulmJ 1 Reply Last reply
                0
                • mandruk1331M mandruk1331

                  @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

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  mandruk1331M 1 Reply Last reply
                  0
                  • jsulmJ jsulm

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

                    mandruk1331M Offline
                    mandruk1331M Offline
                    mandruk1331
                    wrote on last edited by
                    #9

                    @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

                    Mandruk1331

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      When compiling the library or the application ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved