My code uses large set of libraries that I don't want to be compiled everytime I compile my program, so I want to use a precompiled header to include the libraries. I currently use visual studio 2008 as my IDE. The following is what I have tried so far.
stdafx.h (precompiled header)
MyProg.hCode:#include <library1.h> #include <library2.h> . . . #include <libraryN.h>
MyProg.cppCode:#include "stdafx.h" class MyProg { ... }
client.cppCode:#include "stdafx.h" #include "MyProg.h" MyProg::MyProg() { ... } . . .
The above code compiles fine, but then as soon as I remove #include "stdafx.h" from MyProg.cpp, I get the following compile error.Code:#include "stdafx.h"" #include "MyProg.h" int main() { MyProg myProg; ... }
1>MyProg.cpp : warning C4627: '#include "MyProg.h"': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>MyProg.cpp : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
I want to remove #include "stdafx.h" from the cpp file because I am including MyProg.h already which includes stdafx.h, and I thought that including it again in the cpp file would be redundant. Also, the similar errors occur when I remove the same line from the client.cpp. I tried compiling stdafx.h and then compiling MyProg.cpp, but the error still occured. What is happening? Is there a fault in my logic? Thanks in advance.



LinkBack URL
About LinkBacks




CornedBee