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. how to statically link .a to qt (solved)
Forum Updated to NodeBB v4.3 + New Features

how to statically link .a to qt (solved)

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 5.3k Views 4 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.
  • T tarod.net

    @houmingc As I said before, you don't need to put the text "lib" if the library begins with those letters.

    So in your case, you should write the next line:

    LIBS += -L/home/git1/TrainKochi33 -lQLogLib
    
    H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #7

    Sir, static library name itself is libQLogLib.
    Initially a third-party pass me .c and .h files
    I compile them with error, in the end i ask them for .a file.
    Now i can't static link them into my GUI.

    Below is my pro file

    QT          += core gui
    QT          += network
    QT          +=gui
    QT          +=gui declarative
    QT       += widgets
    QT       += multimedia
    QT       += multimediawidgets
    QT       += xml
    
    
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = TrainKochi33
    TEMPLATE = app
    
    CONFIG += c++11
    #CONFIG += -static libQLogLib
    
    win32:LIBS += -lrt
    
    SOURCES += main.cpp\
            mainwindow.cpp \
        threada.cpp \
        mytimer.cpp \
        functions.cpp \
        i2c.cpp
    
    HEADERS  += mainwindow.h \
        threada.h \
        mytimer.h \
        functions.h \
        i2c.h \
        includes.h \
        CLogMsgQ.h \
        CMsgQ.h \
        Common_Logging.h
    
    #INCLUDEPATH += libQLogLib.a
    
    LIBS += -L\home\git1\TrainKochi33 -llibQLogLib
    
    FORMS    += mainwindow.ui
    
    #DISTFILES += \
    #    libQLogLib.a
    
    
    #INCLUDEPATH += /home/git1/TrainKochi33
    
    #CONFIG += libQLogLib.a
    T 1 Reply Last reply
    0
    • H Offline
      H Offline
      houmingc
      wrote on last edited by
      #8

      I try another method, documented below:-

      Add Library <Right-clip Project file>
      Select External library, In Library File, select libQLogLib.a
      Clean
      run qmake
      build
      error: cannot find -lQLoglib

      1 Reply Last reply
      0
      • H houmingc

        Sir, static library name itself is libQLogLib.
        Initially a third-party pass me .c and .h files
        I compile them with error, in the end i ask them for .a file.
        Now i can't static link them into my GUI.

        Below is my pro file

        QT          += core gui
        QT          += network
        QT          +=gui
        QT          +=gui declarative
        QT       += widgets
        QT       += multimedia
        QT       += multimediawidgets
        QT       += xml
        
        
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        TARGET = TrainKochi33
        TEMPLATE = app
        
        CONFIG += c++11
        #CONFIG += -static libQLogLib
        
        win32:LIBS += -lrt
        
        SOURCES += main.cpp\
                mainwindow.cpp \
            threada.cpp \
            mytimer.cpp \
            functions.cpp \
            i2c.cpp
        
        HEADERS  += mainwindow.h \
            threada.h \
            mytimer.h \
            functions.h \
            i2c.h \
            includes.h \
            CLogMsgQ.h \
            CMsgQ.h \
            Common_Logging.h
        
        #INCLUDEPATH += libQLogLib.a
        
        LIBS += -L\home\git1\TrainKochi33 -llibQLogLib
        
        FORMS    += mainwindow.ui
        
        #DISTFILES += \
        #    libQLogLib.a
        
        
        #INCLUDEPATH += /home/git1/TrainKochi33
        
        #CONFIG += libQLogLib.a
        T Offline
        T Offline
        tarod.net
        wrote on last edited by
        #9

        @houmingc Perhaps I didn't explain myself properly.

        If the library is named libXXX.a or libXXX.so, you don't need to put the lib prefix in your qmake or Makefile.

        More info here:

        http://stackoverflow.com/questions/6231206/lib-prefix-on-libraries

        Besides, you pro file has a wrong line. Change this one:

        LIBS += -L\home\git1\TrainKochi33 -llibQLogLib
        

        And use this one instead:

        LIBS += -L/home/git1/TrainKochi33 -lQLogLib
        

        "Individually, we are one drop. Together, we are an ocean."

        1 Reply Last reply
        0
        • R Offline
          R Offline
          roseicollis
          wrote on last edited by roseicollis
          #10

          Hi, I do it this way (i'm working on unix):

          unix:!macx: LIBS += -L$$PWD/../../Project1/Release/ -libOne
          INCLUDEPATH += $$PWD/../../LibOne
          DEPENDPATH += $$PWD/../../LibOne/Release
          unix:!macx: PRE_TARGETDEPS += $$PWD/../../Project1/Release/libOne.a
          

          I use all this 4 lines for every lib I need. In this case my lib is named "libOne.a" and my paths structure is something like this: ( so you can understand it better)

          workspace (folder)
          |-----QtProject (folder)
          |               |-Myproject (folder)
          |                       |- MyProject.exe  // so from here u have to go up 2 steps (that's why I have   "$$PWD/../../"
          |-----LibOne (Folder)
          |            |-Release (folder)
          |            |      |- libOne.a  (The file I want)
          |            |- Debug (folder) ...
          

          Hope it helps you.

          T 1 Reply Last reply
          0
          • R roseicollis

            Hi, I do it this way (i'm working on unix):

            unix:!macx: LIBS += -L$$PWD/../../Project1/Release/ -libOne
            INCLUDEPATH += $$PWD/../../LibOne
            DEPENDPATH += $$PWD/../../LibOne/Release
            unix:!macx: PRE_TARGETDEPS += $$PWD/../../Project1/Release/libOne.a
            

            I use all this 4 lines for every lib I need. In this case my lib is named "libOne.a" and my paths structure is something like this: ( so you can understand it better)

            workspace (folder)
            |-----QtProject (folder)
            |               |-Myproject (folder)
            |                       |- MyProject.exe  // so from here u have to go up 2 steps (that's why I have   "$$PWD/../../"
            |-----LibOne (Folder)
            |            |-Release (folder)
            |            |      |- libOne.a  (The file I want)
            |            |- Debug (folder) ...
            

            Hope it helps you.

            T Offline
            T Offline
            tarod.net
            wrote on last edited by
            #11

            @roseicollis I don't know how Unix works, but at least in Linux, it's not necessary the prefix libwhen you're linking a library named lib<xxx>.so (or .a)

            Info: http://www.rapidtables.com/code/linux/gcc/gcc-l.htm

            "Individually, we are one drop. Together, we are an ocean."

            R H 2 Replies Last reply
            0
            • T tarod.net

              @roseicollis I don't know how Unix works, but at least in Linux, it's not necessary the prefix libwhen you're linking a library named lib<xxx>.so (or .a)

              Info: http://www.rapidtables.com/code/linux/gcc/gcc-l.htm

              R Offline
              R Offline
              roseicollis
              wrote on last edited by
              #12

              @tarod.net neither do I hehe I'm new on this but I had to work on a fedora with Qt and as this worked fine for me, I thought it could help @houmingc so I posted an example of my case. Even if you don't need to put the "lib" it doesn't mean that putting it its wrong and as shown with my example, it works too :) In my case if its possible I prefer to put the entire name or path so its more clear to understand.

              Anyway its always nice to learn new things so thanks for the info and the link! :) I'll keep it in mind the next time

              T 1 Reply Last reply
              0
              • R roseicollis

                @tarod.net neither do I hehe I'm new on this but I had to work on a fedora with Qt and as this worked fine for me, I thought it could help @houmingc so I posted an example of my case. Even if you don't need to put the "lib" it doesn't mean that putting it its wrong and as shown with my example, it works too :) In my case if its possible I prefer to put the entire name or path so its more clear to understand.

                Anyway its always nice to learn new things so thanks for the info and the link! :) I'll keep it in mind the next time

                T Offline
                T Offline
                tarod.net
                wrote on last edited by
                #13

                @roseicollis Great! Thank you! :)

                "Individually, we are one drop. Together, we are an ocean."

                H 1 Reply Last reply
                0
                • T tarod.net

                  @roseicollis Great! Thank you! :)

                  H Offline
                  H Offline
                  houmingc
                  wrote on last edited by
                  #14

                  Thanks you. it worked

                  1 Reply Last reply
                  0
                  • T tarod.net

                    @roseicollis I don't know how Unix works, but at least in Linux, it's not necessary the prefix libwhen you're linking a library named lib<xxx>.so (or .a)

                    Info: http://www.rapidtables.com/code/linux/gcc/gcc-l.htm

                    H Offline
                    H Offline
                    houmingc
                    wrote on last edited by
                    #15

                    Someone direct me to insert the line below and it solved my problem.
                    Can someone explain what this line of code do in Qt project?

                    unix|win32: LIBS +=-lrt

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

                      @houmingc this line means: on either unix or win32 link to the rt library

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

                      H 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        @houmingc this line means: on either unix or win32 link to the rt library

                        H Offline
                        H Offline
                        houmingc
                        wrote on last edited by houmingc
                        #17

                        Thanks.
                        Where is rt library in ubuntu?
                        How to check if rt library is install in ubuntu and install it? i try " locate librt "
                        Why is it not linked automatically?

                        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