views:

209

answers:

3

So, I have to use precompiled headers in my VS 2005 project. Now I have a shared source file that does not have a #include "stdafx.h"... How can I include the shared source file in my project without adding stdafx.h to the top of the source file and without turning off precompiled headers??

+4  A: 

File properties -> C/C++ -> Precompiled Headers -> Create/Use precompiled headers -> Not using ...

Georg Fritzsche
oh snap. I figured it was something simple like that and I'm just being noob. Thanks... I'm still getting familiar with VS :)
Polaris878
This turns off PCH, which is exactly what the OP wants to avoid... Use /FI, instead.
Xavier Nodet
This option allows you to turns off pch for this file - which probably is exactly what the op wants. Where did you get your interpretation of the op wanting to use precompiled headers for the source file from?
Georg Fritzsche
Would also be curious what the down-vote was for.
Georg Fritzsche
+1  A: 

Look in the properties (context menu) for that file, in the C/C++ - Precompiled Header section.

Change "Create/Use Precompiled Header" to "Not Using Precompiled Headers".

Note - I just checked this in VC++2003 - the option might have moved in VC++2005 or 2008, but I doubt it. Even if it has moved, though, it shouldn't be hard to find.

Steve314
Yeah I wasn't sure if this was specific to MFC... I've never used pre-compiled headers before. Thanks!
Polaris878
This turns off PCH... Use /FI, instead.
Xavier Nodet
@Xavier - It turns off PCH for *ONE* *SPECIFIC* cpp file. This is rarely a big deal, and can be beneficial. If every header for the project is included by a single stdafx.h header, which is included by every cpp file (as VC++ encourages), *any* change to *any* header causes *every* cpp file in the whole project to need rebuilding. Of course that suggests explicitly selecting different precompiled header files for different cpp files - but the options are pretty obvious, on the same page as the "Not Using..." option, so why state the obvious - esp as it's not always worth the hassle.
Steve314
A: 

You could also use the 'Force Include' option: "This option has the same effect as specifying the file with double quotation marks in an #include directive on the first line of every source file specified on the command line, in the CL environment variable, or in a command file."

Very handy to introduce PreCompiled Headers without changing all the source files...

Xavier Nodet