User forums > Help

GNU GCC Compiler is compiling REALLY slow.

<< < (7/8) > >>

thomas:
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.
In my understanding, selecting the commandline in the compiler log, copying that, and pasting it into a DOS window should produce a .pch with exactly the same compile options from a header file. It does indeed create .pch files, but it makes no difference in compile times.
A project which compiles in 38 +1/-1 seconds before, compiles in 38 +1/-1 seconds afterwards.

Is there a special magical incantation you need?

Urxae:
To start, it's .gch in gcc not .pch.
Off the top of my head you also didn't mention an important condition: the precompiled header must be #included before any C(++) symbols in a file. In practice this means it must be the first #include (or #included as the first thing in the first #include, or in its first #include, etc.) and you can't put anything before that #include but non-#include preprocessor directives.
Also, any #defines before the #include may not affect the precompiled header.

While posting i've looked up the exact conditions from the gcc 3.4.4 manual section on precompiled headers:

--- Quote ---A precompiled header file can be used only when these conditions apply:

    * Only one precompiled header can be used in a particular compilation.
    * A precompiled header can't be used once the first C token is seen. You can have preprocessor directives before a precompiled header; you can even include a precompiled header from inside another header, so long as there are no C tokens before the #include.
    * The precompiled header file must be produced for the same language as the current compilation. You can't use a C precompiled header for a C++ compilation.
    * The precompiled header file must be produced by the same compiler version and configuration as the current compilation is using. The easiest way to guarantee this is to use the same compiler binary for creating and using precompiled headers.
    * Any macros defined before the precompiled header (including with -D) must either be defined in the same way as when the precompiled header was generated, or must not affect the precompiled header, which usually means that the they don't appear in the precompiled header at all.
    * Certain command-line options must be defined in the same way as when the precompiled header was generated. At present, it's not clear which options are safe to change and which are not; the safest choice is to use exactly the same options when generating and using the precompiled header.
--- End quote ---
(emphasis added)

thomas:
Right, I forgot to mention that C token condition.

The only thing that appears before #include is /* description of file */, and that is surely not considered a C token, is it?

tiwag:

--- Quote from: thomas on October 09, 2005, 03:55:59 pm ---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....
--- End quote ---

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
;-)




--- Code: ---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
--- End code ---





[attachment deleted by admin]

thomas:
Thanks, will be first thing I try tomorrow morning :)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version