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. Additional info upon compiling with Qt Creator
QtWS25 Last Chance

Additional info upon compiling with Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 289 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on 15 Oct 2023, 06:20 last edited by
    #1

    how to test if my PCH header is set pre-compiled, and my complier does not compile this particular header?
    https://forum.qt.io/topic/150819/how-to-use-precompiled-headers-pch-for-c-with-qt/6

    C C 2 Replies Last reply 15 Oct 2023, 07:21
    0
    • J JacobNovitsky referenced this topic on 15 Oct 2023, 06:20
    • J JacobNovitsky
      15 Oct 2023, 06:20

      how to test if my PCH header is set pre-compiled, and my complier does not compile this particular header?
      https://forum.qt.io/topic/150819/how-to-use-precompiled-headers-pch-for-c-with-qt/6

      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 15 Oct 2023, 07:21 last edited by
      #2

      Look at the compiler line if the pch is included.

      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
      • J JacobNovitsky
        15 Oct 2023, 06:20

        how to test if my PCH header is set pre-compiled, and my complier does not compile this particular header?
        https://forum.qt.io/topic/150819/how-to-use-precompiled-headers-pch-for-c-with-qt/6

        C Offline
        C Offline
        ChrisW67
        wrote on 15 Oct 2023, 07:21 last edited by ChrisW67
        #3

        @JacobNovitsky Do you really distrust your tools that much?

        1. You can see that the header file that you identified for precompilation is precompiled by looking at the commands executed when you run make. So, for my example in the other thread on this topic (which, incidentally was also provided in this thread), using GCC:
        $ make
        g++ -pipe -O2 -std=gnu++1z -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../test -I. -I/home/chrisw/Qt/6.6.0/gcc_64/include -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtGui -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtCore -I. -I/home/chrisw/Qt/6.6.0/gcc_64/mkspecs/linux-g++ -x c++-header -c ../test/precompiled.h -o test.gch/c++
        
        1. You can see that this step created precompiled versions of the headers (typically a large, indexed, binary file):
        $ ls -l test.gch/c++
        -rw-rw-r-- 1 chrisw chrisw 122374516 Oct 15 16:56 test.gch/c++
        $ file test.gch/c++ 
        test.gch/c++: GCC precompiled header (version 014) for C++
        
        1. You can see that the precompiled header output file is included when compiling all subsequent C++ files, the -include test option, and before any other:
        g++ -c -include test -pipe -O2 -std=gnu++1z -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../test -I. -I/home/chrisw/Qt/6.6.0/gcc_64/include -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtGui -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtCore -I. -I/home/chrisw/Qt/6.6.0/gcc_64/mkspecs/linux-g++ -o main.o ../test/main.cpp
        
        1. You can test that the pre-compiled headers are found and valid by adding the -H option to the compilation at 3.
        $ g++ -H -c -include test -pipe -O2 -std=gnu++1z -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../test -I. -I/home/chrisw/Qt/6.6.0/gcc_64/include -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtGui -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtCore -I. -I/home/chrisw/Qt/6.6.0/gcc_64/mkspecs/linux-g++ -o main.o ../test/main.cpp
        ! ./test.gch/c++
        . ../test/widget.h
        .. /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QWidget
        ... /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/qwidget.h
        . /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QApplication
        .. /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/qapplication.h
        Multiple include guards may be useful for:
        /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QApplication
        /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QWidget
        

        You can see the precompiled header was found, marked valid, and used. The 'Multiple include guards' message is a result of using the convenience includes <QApplication> rather than <qapplication.h>. The former includes the latter which does have an include guard.

        At this point you trust that the pre-processor and compiler is doing the right thing.
        If you have a non-trivial program, which clearly you do not, then compilation time will generally be measurably improved with the correct content in the precompiled headers.

        J 1 Reply Last reply 15 Oct 2023, 23:54
        2
        • C ChrisW67
          15 Oct 2023, 07:21

          @JacobNovitsky Do you really distrust your tools that much?

          1. You can see that the header file that you identified for precompilation is precompiled by looking at the commands executed when you run make. So, for my example in the other thread on this topic (which, incidentally was also provided in this thread), using GCC:
          $ make
          g++ -pipe -O2 -std=gnu++1z -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../test -I. -I/home/chrisw/Qt/6.6.0/gcc_64/include -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtGui -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtCore -I. -I/home/chrisw/Qt/6.6.0/gcc_64/mkspecs/linux-g++ -x c++-header -c ../test/precompiled.h -o test.gch/c++
          
          1. You can see that this step created precompiled versions of the headers (typically a large, indexed, binary file):
          $ ls -l test.gch/c++
          -rw-rw-r-- 1 chrisw chrisw 122374516 Oct 15 16:56 test.gch/c++
          $ file test.gch/c++ 
          test.gch/c++: GCC precompiled header (version 014) for C++
          
          1. You can see that the precompiled header output file is included when compiling all subsequent C++ files, the -include test option, and before any other:
          g++ -c -include test -pipe -O2 -std=gnu++1z -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../test -I. -I/home/chrisw/Qt/6.6.0/gcc_64/include -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtGui -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtCore -I. -I/home/chrisw/Qt/6.6.0/gcc_64/mkspecs/linux-g++ -o main.o ../test/main.cpp
          
          1. You can test that the pre-compiled headers are found and valid by adding the -H option to the compilation at 3.
          $ g++ -H -c -include test -pipe -O2 -std=gnu++1z -Wall -Wextra -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../test -I. -I/home/chrisw/Qt/6.6.0/gcc_64/include -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtGui -I/home/chrisw/Qt/6.6.0/gcc_64/include/QtCore -I. -I/home/chrisw/Qt/6.6.0/gcc_64/mkspecs/linux-g++ -o main.o ../test/main.cpp
          ! ./test.gch/c++
          . ../test/widget.h
          .. /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QWidget
          ... /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/qwidget.h
          . /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QApplication
          .. /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/qapplication.h
          Multiple include guards may be useful for:
          /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QApplication
          /home/chrisw/Qt/6.6.0/gcc_64/include/QtWidgets/QWidget
          

          You can see the precompiled header was found, marked valid, and used. The 'Multiple include guards' message is a result of using the convenience includes <QApplication> rather than <qapplication.h>. The former includes the latter which does have an include guard.

          At this point you trust that the pre-processor and compiler is doing the right thing.
          If you have a non-trivial program, which clearly you do not, then compilation time will generally be measurably improved with the correct content in the precompiled headers.

          J Offline
          J Offline
          JacobNovitsky
          wrote on 15 Oct 2023, 23:54 last edited by
          #4

          @ChrisW67

          1. how to interpret below?
            file Static_lib.h
            Static_lib.h: C++ source, ASCII text
          PRECOMPILED_HEADER  = Static_lib.h
          
          #pragma once
          #ifndef Static_lib_H
          #define Static_lib_H
          
          
          #if defined __cplusplus
          /* Add C++ includes here */
          #include <QDialog>
          #include <QStandardItemModel>
          #include <QMainWindow>
          #include <QWidget>
          #include <string.h>
          #include <iostream>
          #include <QApplication>
          #endif
          
          1. how to include -H to my building command, if I build program with Qt Creator?
          C 1 Reply Last reply 16 Oct 2023, 01:20
          0
          • J JacobNovitsky
            15 Oct 2023, 23:54

            @ChrisW67

            1. how to interpret below?
              file Static_lib.h
              Static_lib.h: C++ source, ASCII text
            PRECOMPILED_HEADER  = Static_lib.h
            
            #pragma once
            #ifndef Static_lib_H
            #define Static_lib_H
            
            
            #if defined __cplusplus
            /* Add C++ includes here */
            #include <QDialog>
            #include <QStandardItemModel>
            #include <QMainWindow>
            #include <QWidget>
            #include <string.h>
            #include <iostream>
            #include <QApplication>
            #endif
            
            1. how to include -H to my building command, if I build program with Qt Creator?
            C Offline
            C Offline
            ChrisW67
            wrote on 16 Oct 2023, 01:20 last edited by
            #5

            @JacobNovitsky said in Additional info upon compiling with Qt Creator:

            how to interpret below?
            file Static_lib.h
            Static_lib.h: C++ source, ASCII text

            The file command is inspecting the Static_lib.h file and, using its rules, determining that the file contains C++ source or ASCII text. This is indeed the case.

            This file is not the precompiled output file generated by the compilation at step 1. in my example.

            how to include -H to my building command, if I build program with Qt Creator?

            I would not bother. Run it a one file compile once manually, verify the result, and then forget about it.

            I you really must have this extra output in every compilation then add it to the project file's CFLAGS, something like this

            linux-g++: QMAKE_CFLAGS_DEBUG += -H
            
            1 Reply Last reply
            0

            3/5

            15 Oct 2023, 07:21

            • Login

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