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 compile Qt files with g++, VSCode
Forum Updated to NodeBB v4.3 + New Features

how to compile Qt files with g++, VSCode

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.8k 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.
  • L Offline
    L Offline
    Lightshadown
    wrote on last edited by Lightshadown
    #1

    Hi, im using VScode and made a makefile to compile all my files, i used to develop on Netbeans but once i made the switch now i have to compile manually everything, my problems is: i can compile my cpp files but when i try to link all together and create the exe file, i got tons of warnings -- undefined reference to `_imp___ZN11QMetaObject10ConnectionD1Ev' -- and every other Qt related object i have used on my program, i did used UIC for compiling the ui interface thinking that was the problem, still same issue.

    i have like 8 files of my own, but i did notice there are moc files as well (from previous netbeans ide), and i have no idea if the ui.h files need to be included when linking or just on my code

    this is how i compile every file inside the makefile

    COMPILER := C:\Qt\Qt5.11.3\Tools\mingw530_32\bin\g++.exe
    INCLUDE := C:\Qt\Qt5.11.3\5.11.3\mingw53_32\include
    LIB := C:\Qt\Qt5.11.3\5.11.3\mingw53_32\lib
    
    $(COMPILER) -std=c++14 -c -Wall -Wpragmas -mthreads -I $(INCLUDE) -I $(INCLUDE)\QtCore -I $(INCLUDE)\QtSql -I $(INCLUDE)\QtWidgets -I $(INCLUDE)\QtPrintSupport -I $(INCLUDE)\QtNetwork -I $(INCLUDE)\QtGui -I $(INCLUDE)\QtConcurrent -lmingw32 -lshell32 -L C:\MinGW\lib\libiphlpapi.a -L $(LIB) -L $(LIB)\libqtmaind.a -L $(LIB)\libQt5Cored.a -L $(LIB)\libQt5Sqld.a -L $(LIB)\libQt5PrintSupportd.a -L $(LIB)\libQt5Widgetsd.a -L $(LIB)\libQt5Guid.a -L $(LIB)\libQt5Networkd.a -o $(BUILD_DIR)/Silo_Sas.o Cpp/Silo_SaS.cpp  
    

    the code above works but when i try to compile the next code i just get warnings and no exe file

    C:\Qt\Qt5.11.3\Tools\mingw530_32\bin\g++.exe -g build\Debug\Vscode_Windows\Silo_Sas.o build\Debug\Vscode_Windows\main_Pantalla_Principal.o build\Debug\Vscode_Windows\Generales.o build\Debug\Vscode_Windows\Impresora.o build\Debug\Vscode_Windows\Launcher.o build\Debug\Vscode_Windows\Login.o build\Debug\Vscode_Windows\Servidor_Rpi.o -o dist\Debug\Vscode_Windows\Sistema_Silo_Windows_VScode_1_4.exe 
    

    in essence it should link everything im incluiding the libs when i compile, but for some reason behaves like they are not included, the real question is: Do i need to link other libraries? or im missing any flag on the compiler?

    Christian EhrlicherC 1 Reply Last reply
    0
    • L Lightshadown

      Hi, im using VScode and made a makefile to compile all my files, i used to develop on Netbeans but once i made the switch now i have to compile manually everything, my problems is: i can compile my cpp files but when i try to link all together and create the exe file, i got tons of warnings -- undefined reference to `_imp___ZN11QMetaObject10ConnectionD1Ev' -- and every other Qt related object i have used on my program, i did used UIC for compiling the ui interface thinking that was the problem, still same issue.

      i have like 8 files of my own, but i did notice there are moc files as well (from previous netbeans ide), and i have no idea if the ui.h files need to be included when linking or just on my code

      this is how i compile every file inside the makefile

      COMPILER := C:\Qt\Qt5.11.3\Tools\mingw530_32\bin\g++.exe
      INCLUDE := C:\Qt\Qt5.11.3\5.11.3\mingw53_32\include
      LIB := C:\Qt\Qt5.11.3\5.11.3\mingw53_32\lib
      
      $(COMPILER) -std=c++14 -c -Wall -Wpragmas -mthreads -I $(INCLUDE) -I $(INCLUDE)\QtCore -I $(INCLUDE)\QtSql -I $(INCLUDE)\QtWidgets -I $(INCLUDE)\QtPrintSupport -I $(INCLUDE)\QtNetwork -I $(INCLUDE)\QtGui -I $(INCLUDE)\QtConcurrent -lmingw32 -lshell32 -L C:\MinGW\lib\libiphlpapi.a -L $(LIB) -L $(LIB)\libqtmaind.a -L $(LIB)\libQt5Cored.a -L $(LIB)\libQt5Sqld.a -L $(LIB)\libQt5PrintSupportd.a -L $(LIB)\libQt5Widgetsd.a -L $(LIB)\libQt5Guid.a -L $(LIB)\libQt5Networkd.a -o $(BUILD_DIR)/Silo_Sas.o Cpp/Silo_SaS.cpp  
      

      the code above works but when i try to compile the next code i just get warnings and no exe file

      C:\Qt\Qt5.11.3\Tools\mingw530_32\bin\g++.exe -g build\Debug\Vscode_Windows\Silo_Sas.o build\Debug\Vscode_Windows\main_Pantalla_Principal.o build\Debug\Vscode_Windows\Generales.o build\Debug\Vscode_Windows\Impresora.o build\Debug\Vscode_Windows\Launcher.o build\Debug\Vscode_Windows\Login.o build\Debug\Vscode_Windows\Servidor_Rpi.o -o dist\Debug\Vscode_Windows\Sistema_Silo_Windows_VScode_1_4.exe 
      

      in essence it should link everything im incluiding the libs when i compile, but for some reason behaves like they are not included, the real question is: Do i need to link other libraries? or im missing any flag on the compiler?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Lightshadown said in how to compile Qt files with g++, VSCode:

      and made a makefile

      This is wrong - use qmake or better cmake and let the Makefile create them for you, then all other stuff like moc (which you're missing) is added automatically.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      L 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @Lightshadown said in how to compile Qt files with g++, VSCode:

        and made a makefile

        This is wrong - use qmake or better cmake and let the Makefile create them for you, then all other stuff like moc (which you're missing) is added automatically.

        L Offline
        L Offline
        Lightshadown
        wrote on last edited by
        #3

        @Christian-Ehrlicher sso basically makefile is useless in order to compile Qt applications? also, theres a Qt tools addon on vscode market place, is that a good option or just stick with cmake/qmake?

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          Don’t know which tools you mean and which ones suggest building Makefiles manually. cmake/ninja and qmake are the recommended and supported options, as @Christian-Ehrlicher has pointed out.

          Software Engineer
          The Qt Company, Oslo

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

            @Lightshadown said in how to compile Qt files with g++, VSCode:

            basically makefile is useless in order to compile Qt applications?

            No. qmake and /or cmake write a Makefile for you that captures all the elements that compiling and linking a Qt program requires. Both tools take a (typically) straightforward project description. You are, of course, welcome to craft your own Makefile but this will require more knowledge than using either of the tools.

            You would need to at add:

            • Passing any header file containing a QObject class (Q_OBJECT macro) through moc
            • Passing any ui file through uic
            • Add the output of the moc and uic processes to your CPP sources for compilation
            • Add all the relevant Qt libraries to your compiler -L and -l options e.g., -lQt5Core -lQT5Gui
            1 Reply Last reply
            0
            • L Offline
              L Offline
              Lightshadown
              wrote on last edited by
              #6

              Ok i get it, ill check qmake to do my proyect, i tought it was easier to do it manually but i see its more complicated than expected, thanks everyone for your answers, i wont waste more time making my own makefile, i just want to compile it and keep coding

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Lightshadown
                wrote on last edited by
                #7

                just one question , if i add a name with spaces like ui_Sistem window 2.5.h do i simply add it like any other name in the Headers tag inside my project.pro file or it should be "ui_Sistem window 2.5.h" with the quotes?. not sure on that last part, other than that already checking tutorials about qmake

                Christian EhrlicherC 1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #8

                  My mistake, this:

                  Add the output of the moc and uic processes to your CPP sources for compilation

                  should only be the moc output. The UI file output is #included in your sources.

                  As for space in file names, I think double quotes would do it for qmake. However, I would avoid spaces entirely because at some point in the processing the quotes will get lost/be missing and things will break in non-obvious ways.

                  1 Reply Last reply
                  0
                  • L Lightshadown

                    just one question , if i add a name with spaces like ui_Sistem window 2.5.h do i simply add it like any other name in the Headers tag inside my project.pro file or it should be "ui_Sistem window 2.5.h" with the quotes?. not sure on that last part, other than that already checking tutorials about qmake

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Lightshadown said in how to compile Qt files with g++, VSCode:

                    just one question , if i add a name with spaces like ui_Sistem window 2.5.h do i simply add it like any other name in the Headers tag inside my project.pro file or it should be "ui_Sistem window 2.5.h" with the quotes

                    Neither - such a file is generated by uic and must not be added to your source tree.
                    When you use qmake you have to add the ui file to FORMS. And don't add spaces to your file names for your own pleasure - you can be sure it just makes problems somewhere in your build chain.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    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