Additional info upon compiling with Qt Creator
-
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 -
-
Look at the compiler line if the pch is included.
-
@JacobNovitsky Do you really distrust your tools that much?
- 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++
- 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++
- 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
- 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. -
- 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
- how to include -H to my building command, if I build program with Qt Creator?
- how to interpret below?
-
@JacobNovitsky said in Additional info upon compiling with Qt Creator:
how to interpret below?
file Static_lib.h
Static_lib.h: C++ source, ASCII textThe
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