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. Compiling in g++
Forum Updated to NodeBB v4.3 + New Features

Compiling in g++

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 4.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 27 Aug 2021, 05:38 last edited by
    #1

    Currently, one of my personal goals in developing software is to move from compiling my Qt apps in the Qt Creator Software to compiling them in g++; I am relatively new to using g++, and I have had trouble following some online tutorials. What do I need to do to successfully compile my app (especially with the resource and project files) in g++ ?

    1 Reply Last reply
    1
    • C Offline
      C Offline
      ChrisW67
      wrote on 27 Aug 2021, 05:53 last edited by
      #2

      Qt Creator is not a compiler. It was running qmake/cmake for you to create a Makefile (or equivalent), then running make. Make is responsible for running the compiler and linker. To do the same thing outside Qt Creator is fairly straightforward:

      • Write your C++ code
      • Write PRO file that lists your project components (SOURCES, HEADERS, RESOURCES: https://doc.qt.io/qt-5/qmake-tutorial.html)
      • Run qmake from the Qt library set you wish to build with
      • Run make
      • Happy days
      ? 1 Reply Last reply 27 Aug 2021, 19:32
      3
      • C ChrisW67
        27 Aug 2021, 05:53

        Qt Creator is not a compiler. It was running qmake/cmake for you to create a Makefile (or equivalent), then running make. Make is responsible for running the compiler and linker. To do the same thing outside Qt Creator is fairly straightforward:

        • Write your C++ code
        • Write PRO file that lists your project components (SOURCES, HEADERS, RESOURCES: https://doc.qt.io/qt-5/qmake-tutorial.html)
        • Run qmake from the Qt library set you wish to build with
        • Run make
        • Happy days
        ? Offline
        ? Offline
        A Former User
        wrote on 27 Aug 2021, 19:32 last edited by
        #3

        @ChrisW67
        Thank you; I'm a little confused once you get to step 3, is there a good webpage/video to look at?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on 27 Aug 2021, 23:39 last edited by
          #4

          I am going to assume you are using the Qt versions installed by the online installer. On Linux this creates a folder Qt containing one folder for each Qt library version you chose to install (and some other stuff to support Qt Creator). For example:

          chrisw@newton:~/Qt$ ls -l
          total 31492
          drwxrwxr-x  3 chrisw chrisw     4096 Jun  8  2020 5.15.0
          drwxrwxr-x  3 chrisw chrisw     4096 Jun 20 13:24 6.1.1
          -rw-r--r--  1 chrisw chrisw    10174 Jul  4 12:48 components.xml
          ...
          

          Inside each Qt version folder is a complete set of Qt library components and tools identified by compiler(s):

          chrisw@newton:~/Qt$ ls -l 5.15.0/
          total 8
          drwxrwxr-x 13 chrisw chrisw 4096 Jun  8  2020 gcc_64
          -rw-rw-r--  1 chrisw chrisw 2271 May 14  2020 sha1s.txt
          
          chrisw@newton:~/Qt$ ls -l 5.15.0/gcc_64/
          total 76
          drwxr-xr-x  2 chrisw chrisw  4096 Jun  8  2020 bin
          drwxr-xr-x  4 chrisw chrisw  4096 Jun  8  2020 doc
          drwxr-xr-x 88 chrisw chrisw  4096 Jun  8  2020 include
          drwxr-xr-x  5 chrisw chrisw 28672 Jun  8  2020 lib
          drwxr-xr-x  2 chrisw chrisw  4096 Jun  8  2020 libexec
          drwxr-xr-x 76 chrisw chrisw  4096 Jun  8  2020 mkspecs
          drwxr-xr-x  2 chrisw chrisw  4096 Jun  8  2020 phrasebooks
          drwxr-xr-x 33 chrisw chrisw  4096 Jun  8  2020 plugins
          drwxr-xr-x 23 chrisw chrisw  4096 Jun  8  2020 qml
          drwxr-xr-x  2 chrisw chrisw  4096 Jun  8  2020 resources
          drwxr-xr-x  3 chrisw chrisw 12288 Jun  8  2020 translations
          

          If you run the qmake executable from the ~Qt/5.15.0/gcc_64/bin folder against your PRO file it will generate a Makefile that uses the tools and library under ~Qt/5.15.0/gcc_64 and the (in this example) the 64-bit GCC compiler. When you run make your project will be built with those tools and libraries. A Windows install will be similar but you may need to ensure the bundled MingW bin folder is in your PATH.

          So, from top to bottom:

          chrisw@newton:/tmp/demo$ cat main.cpp
          #include <QCoreApplication>
          #include <QDebug>
          
          int main(int argc, char **argv) {
                  QCoreApplication app(argc, argv);
                  qDebug() << "Excellent!";
                  return 0;
          }
          

          A basic PRO file starter can be created for you (one time only, after that you maintain this file yourself):

          chrisw@newton:/tmp/demo$ ~/Qt/5.15.0/gcc_64/bin/qmake -project
          
          chrisw@newton:/tmp/demo$ cat demo.pro
          ######################################################################
          # Automatically generated by qmake (3.1) Sat Aug 28 09:32:14 2021
          ######################################################################
          
          TEMPLATE = app
          TARGET = demo
          INCLUDEPATH += .
          
          # You can make your code fail to compile if you use deprecated APIs.
          # In order to do so, uncomment the following line.
          # Please consult the documentation of the deprecated API in order to know
          # how to port your code away from it.
          # 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
          
          # Input
          SOURCES += main.cpp
          

          Then you create the Makefile:

          chrisw@newton:/tmp/demo$ ~/Qt/5.15.0/gcc_64/bin/qmake 
          
          chrisw@newton:/tmp/demo$ ls 
          demo.pro  main.cpp  Makefile
          

          and build the project:

          chrisw@newton:/tmp/demo$ make
          g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/home/chrisw/Qt/5.15.0/gcc_64/include -I/home/chrisw/Qt/5.15.0/gcc_64/include/QtGui -I/home/chrisw/Qt/5.15.0/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I/home/chrisw/Qt/5.15.0/gcc_64/mkspecs/linux-g++ -o main.o main.cpp
          g++ -Wl,-O1 -Wl,-rpath,/home/chrisw/Qt/5.15.0/gcc_64/lib -o demo main.o   /home/chrisw/Qt/5.15.0/gcc_64/lib/libQt5Gui.so /home/chrisw/Qt/5.15.0/gcc_64/lib/libQt5Core.so -lGL -lpthread   
          
          chrisw@newton:/tmp/demo$ ./demo 
          Excellent!
          
          1 Reply Last reply
          4

          1/4

          27 Aug 2021, 05:38

          • Login

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