I think you're missing some fundamental concept.
The compiler is going to parse and compile every included file every time it compiles a source file (which is every time you change a source file). So for an example, let's say you have the following files:
1 2 3 4
|
// myclass.h
#include <string>
class MyClass { /*... */ };
|
1 2 3 4
|
// stdafx.h
#include <windows.h>
#include <iostream>
#include "myclass.h"
|
1 2 3 4
|
// main.cpp
#include "stdafx.h"
// ...
|
1 2 3 4
|
// support.cpp
#include "stdafx.h"
//...
|
When you build this project,
if you do not have a precompiled header the compiler is going to compile the 2 source files main.cpp and support.cpp. When it does, it will do this:
Compiling main.cpp
- found #include "stdafx.h" in main.cpp, so start compiling stdafx.h
- found #include <windows.h> in stdafx.h, so start compiling windows.h
- found XXX other includes in windows.h, so compile all those headers as well
- found #include <iostream> in stdafx.h, so start compiling that header
- found XXX other includes in iostream, so compile all those as well
- found #include "myclass.h" in stdafx.h, so compile that header
- stdafx.h finish, continue compiling main.cpp
Compiling support.cpp
- found #include "stdafx.h" in support.cpp, so start compiling stdafx.h
- found #include <windows.h> in stdafx.h, so start compiling windows.h
- found XXX other includes in windows.h, so compile all those headers as well
- found #include <iostream> in stdafx.h, so start compiling that header
- found XXX other includes in iostream, so compile all those as well
- found #include "myclass.h" in stdafx.h, so compile that header
- stdafx.h finish, continue compiling support.cpp
Now...
if you make stdafx.h a precompiled header, the compiler will do this instead:
PreCompiling stdafx.h
- found #include <windows.h> in stdafx.h, so start compiling windows.h
- found XXX other includes in windows.h, so compile all those headers as well
- found #include <iostream> in stdafx.h, so start compiling that header
- found XXX other includes in iostream, so compile all those as well
- found #include "myclass.h" in stdafx.h, so compile that header
- stdafx.h is now compiled, put compiled information in a new "stdafx.pch" file
Compiling main.cpp
- found #include "stdafx.h", but I already compiled that header, so no need to compile it again. Just use the info in the existing pch file.
- continue compiling main.cpp
Compiling support.cpp
- found #include "stdafx.h", but I already compiled that header, so no need to compile it again. Just use the info in the existing pch file.
- continue compiling support.cpp
That's all it does. It just compiles the stuff once so it doesn't need to be compiled every time.