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. Cannot link Qt static libraries
Forum Updated to NodeBB v4.3 + New Features

Cannot link Qt static libraries

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.5k Views 1 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.
  • C Offline
    C Offline
    CBenussi
    wrote on last edited by
    #1

    Hi all,

    I want to deploy a stand-alone application for Windows 32 bit with MinGW using Qt Creator.

    I followed this guide to build Qt statically for Windows (MinGW) and the building process went just fine.

    Then, as suggested by the guide, I opened Qt creator and defined a new Kit which uses the new Qt Static version I just built (by linking its qmake.exe). My previously developed project obviously complained (many errors referring to "undefined reference to") when I switched to the other kit that he could not find any reference for the used Qt functions and classes.

    In order to tell Qt how to find the libraries I changed the .pro file as follows (I used the Qt UI for linking libraries):

    # Project created by QtCreator 2016-09-28T14:09:58
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = String_GUI
    TEMPLATE = app
    CONFIG += static
    
    SOURCES += main.cpp\
        fontdaemon.cpp
    
    HEADERS  += fontdaemon.h
    
    INCLUDEPATH += $$PWD/../../../../Qt/Static/5.7.0/include
    DEPENDPATH += $$PWD/../../../../Qt/Static/5.7.0/include
    
    win32: LIBS += -L$$PWD/../../../../Qt/Static/5.7.0/lib/ -lQt5Core //Example of including one library
    win32-g++: PRE_TARGETDEPS += $$PWD/../../../../Qt/Static/5.7.0/lib/libQt5Core.a
    
    

    But even including all the libraries present in the library folder (I put just one for simplicity, but I tried to include all of them), I still get the same number (aboyut 300) of errors "undefined reference to", for example:

    C:\Users\Documents\String_GUI\main.cpp:-1: error: undefined reference to `QApplication::QApplication(int&, char**, int)' 
    

    It seems my project does not find any reference of the Qt tools in the libraries I link it against. Any insight of what could be the problem?

    I have noticed that the static libraries of my Qt static building have the *.a extension instead of the expected (by me) *.lib ; could this be a problem? The compiler anyway does not complain that he cannot find the libraries, so I guess not, but who knows...

    Moreover, how can I know which static libraries I need to link my project against, depending on the Qt header files I include for definition?

    Thanks in advance.

    K 1 Reply Last reply
    0
    • C CBenussi

      Hi all,

      I want to deploy a stand-alone application for Windows 32 bit with MinGW using Qt Creator.

      I followed this guide to build Qt statically for Windows (MinGW) and the building process went just fine.

      Then, as suggested by the guide, I opened Qt creator and defined a new Kit which uses the new Qt Static version I just built (by linking its qmake.exe). My previously developed project obviously complained (many errors referring to "undefined reference to") when I switched to the other kit that he could not find any reference for the used Qt functions and classes.

      In order to tell Qt how to find the libraries I changed the .pro file as follows (I used the Qt UI for linking libraries):

      # Project created by QtCreator 2016-09-28T14:09:58
      #
      #-------------------------------------------------
      
      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = String_GUI
      TEMPLATE = app
      CONFIG += static
      
      SOURCES += main.cpp\
          fontdaemon.cpp
      
      HEADERS  += fontdaemon.h
      
      INCLUDEPATH += $$PWD/../../../../Qt/Static/5.7.0/include
      DEPENDPATH += $$PWD/../../../../Qt/Static/5.7.0/include
      
      win32: LIBS += -L$$PWD/../../../../Qt/Static/5.7.0/lib/ -lQt5Core //Example of including one library
      win32-g++: PRE_TARGETDEPS += $$PWD/../../../../Qt/Static/5.7.0/lib/libQt5Core.a
      
      

      But even including all the libraries present in the library folder (I put just one for simplicity, but I tried to include all of them), I still get the same number (aboyut 300) of errors "undefined reference to", for example:

      C:\Users\Documents\String_GUI\main.cpp:-1: error: undefined reference to `QApplication::QApplication(int&, char**, int)' 
      

      It seems my project does not find any reference of the Qt tools in the libraries I link it against. Any insight of what could be the problem?

      I have noticed that the static libraries of my Qt static building have the *.a extension instead of the expected (by me) *.lib ; could this be a problem? The compiler anyway does not complain that he cannot find the libraries, so I guess not, but who knows...

      Moreover, how can I know which static libraries I need to link my project against, depending on the Qt header files I include for definition?

      Thanks in advance.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @CBenussi

      You might be right with your assumption, but the error message you are showing is referring to a constructor which does not exist.
      QApplication has an integer and pointers to "strings" (char **). I wonder you got the compilation done with this parameter list.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CBenussi
        wrote on last edited by
        #3

        The problem is that Qt is not loading at all the static libraries, since none of the objects I use in my application (QLabel, QLineEdit, QFont...) has a reference to. It compiles perfectly by using the Qt version downloaded with the dll's anyway.

        1 Reply Last reply
        0
        • Roy44R Offline
          Roy44R Offline
          Roy44
          wrote on last edited by
          #4

          *.a are libraries compiled with mingw
          *.lib are libraries compiled with Visual Studio
          QApplication is for graphical I think, so I believe you missed some libraries to link.
          try with Qt5Widgets.a and qmain.a.

          (sorry for my bad english)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CBenussi
            wrote on last edited by
            #5

            I tried to link all the libraries present in lib/, include Qt5Widgets and qmain

            1 Reply Last reply
            0
            • C Offline
              C Offline
              CBenussi
              wrote on last edited by CBenussi
              #6

              Any hint?

              I could have found a problem. When defining the Kit for the Static version of Qt, I get the following warning for the Qt version:
              "no qmlscene installed":

              alt text

              And then under the kit definition qt tells me that: "The compiler MinGW (x86-windows-msys-pe-32bit) may not produce code compatible with the Qt version (x86-windows-unknown-pe-32bit) installed.
              Could this be the cause?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CBenussi
                wrote on last edited by
                #7

                I found the "super silly" problem. I had two versions of MinGW, and I've built the static version of Qt with one, but was defining the kit with the other one. Now it works fine.

                1 Reply Last reply
                1

                • Login

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