[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Precompiled headers do not speed compilation up?
From: |
Markus Dehmann |
Subject: |
Precompiled headers do not speed compilation up? |
Date: |
Mon, 17 Nov 2008 17:30:05 -0800 (PST) |
User-agent: |
G2/1.0 |
I include lots of header files in my code, so compilation is very
slow. I tried speeding it up by using precompiled headers, but that
didn't speed it up at all. Does anyone know why, or have the same
experience?
Here is what I do, as a test:
I have a very simple main.cpp file that doesn't do much, but include
lots of headers:
// main.cpp
#include <iostream>
#include "header1.h"
#include "header2.h"
#include "header3.h"
int main(){
std::cout << "hello";
}
This takes 40 seconds to compile because there is a lot of code in the
header files. Now I do precompilation instead:
// main2.cpp
#include "all.h"
int main(){
std::cout << "hello";
}
// all.h
#include <iostream
#include "header1.h"
#include "header2.h"
#include "header3.h"
// On the command line:
$ g++ all.h
$ g++ -c -o main2.o main2.cpp
Now, each of those two g++ commands takes 40 seconds! I know for sure
that the precompiled header all.h.pch, which is produced by the first g
++ command, is used in the second, since it prints all.h.pch as a
valid used header when I use the g++ option -H.
Why would precompiling the header not help in this situation? Am I
doing it wrong?
Thanks!
Markus
- Precompiled headers do not speed compilation up?,
Markus Dehmann <=