Skip to main content
GameDev.net gamedev.net
🔒 Locked

stdafx.h in .cpp Files

Started by Geometrian Sep 3, 2011 at 8:54 PM 1 replies 2.5k views
Original Post
Geometrian
Geometrian
Hi,

This has been a long-standing problem. I have a very large project, with dozens of source and header files at several levels in a directory structure.

For code clarity, in .cpp files, one should use "#include "../stdafx.h"", "#include "../../stdafx.h"", "#include "../../../stdafx.h"", etc. However, there is a problem with Visual Studio (I have 2010 Ultimate) that only allows "#include "stdafx.h"". You'll get an error:

warning C4627: '#include "../stdafx.h"': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header

The only technical posting I could find of any help was https://connect.micr...details/552449/. Previously, I have been working with workaround 1., which is beyond lame and is confusing. Compiling on other platforms makes that even more problematic. I would like to use workaround 2., but there are multiple levels of files in the directory structure, so just choosing a different name for the precompiled header file doesn't work. The posting was vague, and seemed to imply that it could be done separately for each directory level. I have no idea how to do that, or if that's even possible.

The posting is more than a year old, and nothing has come of it, so I assume it's been forgotten. It's a problem for me though.

Help?
Thanks,
G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]
fastcall22
fastcall22
Try forcing include file "$(ProjectDir)\stdafx.h" in your project settings.

While this will double include stdafx.h (which won't be a problem if stdafx has include guards/pragma onc), it will allow you to include "..\..\stdafx.h" in your source files and maintain compatibility.
Geometrian
Geometrian
Hi,


Try forcing include file "$(ProjectDir)\stdafx.h" in your project settings.

While this will double include stdafx.h (which won't be a problem if stdafx has include guards/pragma onc), it will allow you to include "..\..\stdafx.h" in your source files and maintain compatibility.

I opened the project's properties, and added:$(ProjectDir)\stdafx.h
. . .under "Advanced". Unfortunately, this gives:'#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file
I instead just wrote:stdafx.h
. . . and it seems to work.

The build now takes a little over 10 seconds, as opposed to more than 50 seconds before. I felt like it was even faster the old way (workaround 1), but subsequent tests show that not to be the case.

I'm quite disappointed in Visual Studio for not supporting relative paths in its precompiled headers. That's just lame. MS, get on this!

Anyway, this workaround effectively solves the problem! My thanks!

-G
[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.