Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C2857 Error with Precompiled Headers

912 views
Skip to first unread message

nomad

unread,
Dec 6, 2005, 10:48:02 AM12/6/05
to
I'm trying to build a project with precompiled headers, using the /Yu and /Yc
compiler options. I have the following sort of structure:

MyPrecomp.h
#include "StdAfx.h"
#include "MyGlobals.h"
#include "SomeOtherStuff.h"

"MyGlobals.h" includes various bits, such as <new>, <algorithm>, and
<limits>.

I also have a file called MyPrecomp.cpp. In the Project properties, I set
the /Yu flag, and I specify that the precompiled header is to go through the
file "MyPrecomp.h", and that the actual precompiled header file will be
"MyPrecomp.pch".

I the properties for MyPrecomp.cpp, I set the /Yc flag, and use the same
specifications for "going through" and the pch file as above.

When I try to build, the compiler grabs MyPrecomp.cpp and starts compiling
it, sucking in the headers, and then generates the following error message:

C:\Program Files\[...]\atlcoll.h(1953): error C2857: '#include' statement
specified with the /YcG:\Development\[...]\MyPrecomp.h command-line option
was not found in the source file.

So, what's going on here? Why is atlcoll.h, a header file, complaining about
my precompiled header file? And what does some file down in ATL have to do
with anything?

David Wilkinson

unread,
Dec 6, 2005, 11:04:02 AM12/6/05
to
nomad wrote:

nomad:

I don't think you are supposed to put the stdafx.h in another header;
rather you are supposed to put it first in each .cpp file. Does the
problem go away if you do that?

David Wilkinson

nomad

unread,
Dec 6, 2005, 11:25:04 AM12/6/05
to

"David Wilkinson" wrote:

> I don't think you are supposed to put the stdafx.h in another header;
> rather you are supposed to put it first in each .cpp file. Does the
> problem go away if you do that?

Nope. I changed the setup as follows:

StdAfx.h
#include "MyGlobals.h"

and modified MyGlobals.h to not include StdAfx.h anymore. I renamed my old
MyGlobals.cpp file to be StdAfx.cpp and set its properties the same way. I
get the exact same error message.

nomad

unread,
Dec 6, 2005, 11:27:03 AM12/6/05
to

"nomad" wrote:

> I get the exact same error message.

Well, except that it's complaining about not finding StdAfx.h now instead of
MyPrecomp.h.

nomad

unread,
Dec 6, 2005, 12:01:03 PM12/6/05
to
Okay, I figured out the fix, but I don't know why it works:

In my properties, I had specified the "through file" specification as

$(ProjectDir)MyPrecomp.h

If I specify it instead as

MyPrecomp.h

i.e., leave off the "$(ProjectDir)", everything works. This may have to do
with the fact that my project directory is on my G: drive, not my C: drive,
or it may be because something in the IDE doesn't like the $(ProjectDir)
macro at that point. In any event, this seems to have fixed it.

Only took me a day and a half to track down. Geez, what a crock.

0 new messages