I would be very interested to learn how you do that.
According to the gcc docs, .pch are used if they
a) have the same filename (plus .pch)
b) were compiled using the same compiler version
c) were compiled with the very same compiler settings
I have tried using precompiled headers many times and never managed to squeeze even one second out of it....
attached is a sample project, where you can look how the preceompiled headers with gcc (3.4.4) are working.
the sample it is an ordinary wxWidgets minimal program with a frame.
every source file includes precomp.h first, this file we'll precompile.
Remarks to the following steps:
- 1.) first, i build the project as normal (without precompiled header precomp.h.gch),
it takes 13sec on my old AMD 1800 (Windows XP, MinGW gcc 3.4.4) - 2.) building the precompiled header:
(i played a while to automate this with CodeBlocks custum build commands,
but i didn't find a general solution, so i propose for now the manual creation of the .gch)
from the Build Log i took the commandline for compiling PrecomiledHeadersFrm.cpp and
changed only the file arguments for input (-c) and output (-o) files
from: -c PrecompiledHeadersFrm.cpp -o pch_test_d_dll\PrecompiledHeadersFrm.o
...to: -c precomp.h -o precomp.h.gch - 3.) generate the precompiled header file by running precomp.bat file
- 4.) Rebuild the CodeBlocks project
it takes 2-3sec now
;-)
How to use precompiled headers. // tiwag 051009
1.)
--------------------------------------------------------------------------------
Rebuild without precompiled headers:
--------------------------------------------------------------------------------
Project : Precompiled Headers test
Compiler : GNU GCC Compiler (called directly)
Directory : D:\cpp\_projects\Codeblocks\precompiled headers\test\
--------------------------------------------------------------------------------
Switching to target: Debug Dll
windres.exe -i PrecompiledHeadersApp.rc -J rc -o pch_test_d_dll\PrecompiledHeadersApp.res -O coff -ID:\wx261\Include
mingw32-g++.exe -Wall -g -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fmessage-length=0 -ggdb -Winvalid-pch -D__GNUWIN32__ -D__WXMSW__ -D__WXDEBUG__ -DWXUSINGDLL -DWX_PRECOMP -ID:\wx261\Include -ID:\wx261\lib\gcc_dll\mswd -c PrecompiledHeadersFrm.cpp -o pch_test_d_dll\PrecompiledHeadersFrm.o
mingw32-g++.exe -Wall -g -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fmessage-length=0 -ggdb -Winvalid-pch -D__GNUWIN32__ -D__WXMSW__ -D__WXDEBUG__ -DWXUSINGDLL -DWX_PRECOMP -ID:\wx261\Include -ID:\wx261\lib\gcc_dll\mswd -c PrecompiledHeadersApp.cpp -o pch_test_d_dll\PrecompiledHeadersApp.o
mingw32-g++.exe -LD:\wx261\lib\gcc_dll -o pch_test_d_dll.exe pch_test_d_dll\PrecompiledHeadersFrm.o pch_test_d_dll\PrecompiledHeadersApp.o pch_test_d_dll\PrecompiledHeadersApp.res -mthreads -lkernel32 -luser32 -lgdi32 -lcomctl32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lwxmsw26d -mwindows
Process terminated with status 0 (0 minutes, 13 seconds)
0 errors, 0 warnings
2.)
--------------------------------------------------------------------------------
make precomp.bat:
-----------------
take compiler call g++ string from Build Log and
change: -c PrecompiledHeadersFrm.cpp -o pch_test_d_dll\PrecompiledHeadersFrm.o
to: -c precomp.h -o precomp.h.gch
--------------------------------------------------------------------------------
g++.exe -Wall -g -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fmessage-length=0 -ggdb -Winvalid-pch -D__GNUWIN32__ -D__WXMSW__ -D__WXDEBUG__ -DWXUSINGDLL -DWX_PRECOMP -ID:\wx261\Include -ID:\wx261\lib\gcc_dll\mswd -c precomp.h -o precomp.h.gch
3.)
--------------------------------------------------------------------------------
precompiled header for wx-widgets
--------------------------------------------------------------------------------
precomp.h
precomp.h.gch 43.463.029 bytes
4.)
--------------------------------------------------------------------------------
Rebuild with precompiled headers:
--------------------------------------------------------------------------------
Project : Precompiled Headers test
Compiler : GNU GCC Compiler (called directly)
Directory : D:\cpp\_projects\Codeblocks\precompiled headers\
--------------------------------------------------------------------------------
Switching to target: Debug Dll
windres.exe -i PrecompiledHeadersApp.rc -J rc -o pch_test_d_dll\PrecompiledHeadersApp.res -O coff -ID:\wx261\Include
mingw32-g++.exe -Wall -g -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fmessage-length=0 -ggdb -Winvalid-pch -D__GNUWIN32__ -D__WXMSW__ -D__WXDEBUG__ -DWXUSINGDLL -DWX_PRECOMP -ID:\wx261\Include -ID:\wx261\lib\gcc_dll\mswd -c PrecompiledHeadersFrm.cpp -o pch_test_d_dll\PrecompiledHeadersFrm.o
mingw32-g++.exe -Wall -g -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fmessage-length=0 -ggdb -Winvalid-pch -D__GNUWIN32__ -D__WXMSW__ -D__WXDEBUG__ -DWXUSINGDLL -DWX_PRECOMP -ID:\wx261\Include -ID:\wx261\lib\gcc_dll\mswd -c PrecompiledHeadersApp.cpp -o pch_test_d_dll\PrecompiledHeadersApp.o
mingw32-g++.exe -LD:\wx261\lib\gcc_dll -o pch_test_d_dll.exe pch_test_d_dll\PrecompiledHeadersFrm.o pch_test_d_dll\PrecompiledHeadersApp.o pch_test_d_dll\PrecompiledHeadersApp.res -mthreads -lkernel32 -luser32 -lgdi32 -lcomctl32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lwxmsw26d -mwindows
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings
[attachment deleted by admin]