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. Looking for good explanation of creation process of Static Lib and it's Test App
Qt 6.11 is out! See what's new in the release blog

Looking for good explanation of creation process of Static Lib and it's Test App

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 1.4k Views 2 Watching
  • 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.
  • sitesvS Offline
    sitesvS Offline
    sitesv
    wrote on last edited by
    #1

    Hi!
    Could you please explain about the creation of static lib with a test app for both OS like Linux and Windows with the right relative paths? I'm in a mess. What is work fine in Linux, cannot be recompiled and work in Windows. There is magic with paths, shadow builds and etc.

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

      Hi,

      Can you show your .pro files ?

      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
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by gde23
        #3

        I guess you need to provide a little bit more information.

        • What make toolkit are you using?
        • Is the lib in the same project as the executable
        • What exactly is the problem you have?
        1 Reply Last reply
        0
        • sitesvS Offline
          sitesvS Offline
          sitesv
          wrote on last edited by sitesv
          #4

          @SGaist , @gde23
          test app pro file:

          QT -= gui
          
          CONFIG += c++11 console
          CONFIG -= app_bundle
          
          DEFINES += QT_DEPRECATED_WARNINGS
          
          SOURCES += \
                  main.cpp
          
          # Default rules for deployment.
          qnx: target.path = /tmp/$${TARGET}/bin
          else: unix:!android: target.path = /opt/$${TARGET}/bin
          !isEmpty(target.path): INSTALLS += target
          
          win32
          {
              CONFIG(release, debug|release){
                  LIBS += -L$$PWD/../project1/cpp/dll/mylib/release/ -lmylib
                  INCLUDEPATH += $$PWD/../project1/cpp/dll/mylib/release
                  DEPENDPATH += $$PWD/../project1/cpp/dll/mylib/release
              }
              CONFIG(debug, debug|release){
                  LIBS += -L$$PWD/../project1/cpp/dll/mylib/debug/ -lmylib
                  INCLUDEPATH += $$PWD/../project1/cpp/dll/mylib/debug
                  DEPENDPATH += $$PWD/../project1/cpp/dll/mylib/debug
              }
          }
          unix
          {
              LIBS += -L$$PWD/../project1/cpp/dll/mylib/ -lmylib
              INCLUDEPATH += $$PWD/../project1/cpp/dll/mylib
              DEPENDPATH += $$PWD/../project1/cpp/dll/mylib
          }
          

          Lib Pro file:

          QT       -= gui
          TARGET = GET_INF_HUB
          TEMPLATE = lib
          DEFINES += GET_INF_HUB_LIBRARY
          DEFINES += QT_DEPRECATED_WARNINGS
          SOURCES += \
                  mylib.cpp
          HEADERS += \
                  mylib.h \
                  mylib_global.h 
          unix {
              target.path = /usr/lib
              INSTALLS += target
          }
          

          Static lib added to test app like an external lib.

          In Linux test app starts without problems.
          In Windows, first of all, I need to uncheck Shadow build in test and lib apps... And after compilation there is an error msg:
          main.obj:-1: error: LNK2019: unresolved external symbol __imp__Start referenced in function _main
          I have cleaned tmp files and folders... But there is no effect...

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

            First thing: are you sure your library is properly statically built on Windows ?

            If not, then I would guess you are not properly exporting the symbols from that library hence the missing symbol.

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

            sitesvS 1 Reply Last reply
            0
            • SGaistS SGaist

              First thing: are you sure your library is properly statically built on Windows ?

              If not, then I would guess you are not properly exporting the symbols from that library hence the missing symbol.

              sitesvS Offline
              sitesvS Offline
              sitesv
              wrote on last edited by
              #6

              @SGaist said in Looking for good explanation of creation process of Static Lib and it's Test App:

              First thing: are you sure your library is properly statically built on Windows ?

              How I should check this?

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

                Are you properly setting the static flag in your library project ? Do you get a .dll when building on Windows ?

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

                sitesvS 1 Reply Last reply
                0
                • SGaistS SGaist

                  Are you properly setting the static flag in your library project ? Do you get a .dll when building on Windows ?

                  sitesvS Offline
                  sitesvS Offline
                  sitesv
                  wrote on last edited by
                  #8

                  @SGaist said in Looking for good explanation of creation process of Static Lib and it's Test App:

                  Are you properly setting the static flag in your library project ? Do you get a .dll when building on Windows ?

                  Yes. Dll and Lib files are created after building lib.

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

                    Then your library is not build statically and you are not properly exporting symbols.

                    For that second part see here.

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

                    sitesvS 1 Reply Last reply
                    3
                    • SGaistS SGaist

                      Then your library is not build statically and you are not properly exporting symbols.

                      For that second part see here.

                      sitesvS Offline
                      sitesvS Offline
                      sitesv
                      wrote on last edited by
                      #10

                      @SGaist thanks. I will recode my lib.

                      I there any way to debug dynamic/static lib?

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

                        Sure, use a debug build of your library.

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

                        sitesvS 1 Reply Last reply
                        2
                        • SGaistS SGaist

                          Sure, use a debug build of your library.

                          sitesvS Offline
                          sitesvS Offline
                          sitesv
                          wrote on last edited by
                          #12

                          @SGaist ones more Q:
                          But how the same project works in Linux?

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

                            Because the symbol exportation does not work the same on Linux.

                            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
                            2
                            • gde23G Offline
                              gde23G Offline
                              gde23
                              wrote on last edited by
                              #14

                              When you have a library under windows you need to explicitly export the symbols.
                              On linux it is not necessary because the symbols are managed in another way.

                              Typically this is done using a preprocessor define that you add at any function / class that you wanna export like (just look it up on stackoverflow)

                              #ifdef WIN32
                                  #define DECL_EXPORT __declspec(dllexport)
                                  #define DECL_IMPORT __declspec(dllimport)
                              #else
                                  #define DECL_EXPORT
                                  #define DECL_IMPORT
                              #endif
                              
                              SGaistS 1 Reply Last reply
                              0
                              • gde23G gde23

                                When you have a library under windows you need to explicitly export the symbols.
                                On linux it is not necessary because the symbols are managed in another way.

                                Typically this is done using a preprocessor define that you add at any function / class that you wanna export like (just look it up on stackoverflow)

                                #ifdef WIN32
                                    #define DECL_EXPORT __declspec(dllexport)
                                    #define DECL_IMPORT __declspec(dllimport)
                                #else
                                    #define DECL_EXPORT
                                    #define DECL_IMPORT
                                #endif
                                
                                SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @gde23 said in Looking for good explanation of creation process of Static Lib and it's Test App:

                                When you have a library under windows you need to explicitly export the symbols.
                                On linux it is not necessary because the symbols are managed in another way.

                                Typically this is done using a preprocessor define that you add at any function / class that you wanna export like (just look it up on stackoverflow)

                                #ifdef WIN32
                                    #define DECL_EXPORT __declspec(dllexport)
                                    #define DECL_IMPORT __declspec(dllimport)
                                #else
                                    #define DECL_EXPORT
                                    #define DECL_IMPORT
                                #endif
                                

                                That is incomplete, The macro to use depend whether you are building the library or using it. See the dedicated chapter in Qt's documentation for a clean way to handle that.

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

                                gde23G 1 Reply Last reply
                                1
                                • sitesvS Offline
                                  sitesvS Offline
                                  sitesv
                                  wrote on last edited by sitesv
                                  #16

                                  @SGaist I checked my code... It is matches to link.
                                  But lib and dll files are created.

                                  Should this code be in pro file:

                                  CONFIG += staticlib
                                  

                                  ?

                                  So, I have included this string to pro and as a result a lib file only.

                                  Could you please see my test apps? ==> app

                                  1 Reply Last reply
                                  0
                                  • SGaistS SGaist

                                    @gde23 said in Looking for good explanation of creation process of Static Lib and it's Test App:

                                    When you have a library under windows you need to explicitly export the symbols.
                                    On linux it is not necessary because the symbols are managed in another way.

                                    Typically this is done using a preprocessor define that you add at any function / class that you wanna export like (just look it up on stackoverflow)

                                    #ifdef WIN32
                                        #define DECL_EXPORT __declspec(dllexport)
                                        #define DECL_IMPORT __declspec(dllimport)
                                    #else
                                        #define DECL_EXPORT
                                        #define DECL_IMPORT
                                    #endif
                                    

                                    That is incomplete, The macro to use depend whether you are building the library or using it. See the dedicated chapter in Qt's documentation for a clean way to handle that.

                                    gde23G Offline
                                    gde23G Offline
                                    gde23
                                    wrote on last edited by
                                    #17

                                    @SGaist You are right. I forgot to mention that part.
                                    @sitesv The dll will be created also if you do not export the symbols. But the exe will not know about the function/class inside the dll so it will not find them.
                                    Did you include the defines as in the description SGaist posted?

                                    sitesvS 1 Reply Last reply
                                    0
                                    • gde23G gde23

                                      @SGaist You are right. I forgot to mention that part.
                                      @sitesv The dll will be created also if you do not export the symbols. But the exe will not know about the function/class inside the dll so it will not find them.
                                      Did you include the defines as in the description SGaist posted?

                                      sitesvS Offline
                                      sitesvS Offline
                                      sitesv
                                      wrote on last edited by sitesv
                                      #18

                                      @gde23 said in Looking for good explanation of creation process of Static Lib and it's Test App:

                                      @SGaist You are right. I forgot to mention that part.
                                      @sitesv The dll will be created also if you do not export the symbols. But the exe will not know about the function/class inside the dll so it will not find them.
                                      Did you include the defines as in the description SGaist posted?

                                      Yes. I checked it. Could you view my code by this link?

                                      UPD: I inserted the line "extern int test();" to main.cpp. And voila!

                                      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