Re: VC2005 Pro: IDE (Compiler ?) can't find Stdafx.h

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx> wrote in message
news:OVsisttCGHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
> "David F" <David-White@xxxxxxxxxxxxx> wrote in message
> news:Uy6sf.403$Hl6.237@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
> > news:Os9U3BqCGHA.3784@xxxxxxxxxxxxxxxxxxxxxxx
> >>
> >> Your first post said you have #include "stdafx.h" in your code but
> >> you do not have a stdafx.h file in your project directory. In other
> >> words you told the compiler to include a file that does not exist.
> >> If all this is true then that's why it issues the "does not find"
> >> error message. I hope that makes sense? Also, I don't understand
> >> why you
> >
> > The answer is apparently not. I forgot that, as mark wrote, that
> > stdafx.h/.cpp are produced by the compiler if I have the #include
> > "stdafx.h" statement in my source files. So the problem then shifts
> > to not why does not the compiler find stdafx.h (that is now clear)
> > but rather why does not it
> > producing them (or is it possible it producing them in some weird
> > place?!).
>
> The compiler does not produce stdafx.h/.cpp. The compiler does what
> compilers always do; it produces binary output from source code. You have
to
> produce the source code yourself. A precompiled header has a .pch
extension.
> That is the file that the compiler produces.

With VS2003 generation, I always chose Empty Project checked ON and
Precompiled Headers checked OFF. Now, whether it was the compiler, the
preprocessor, the IDE or whatever, something DID produce for me the
stdafx.h+.cpp as well as some other resource files, etc. I was not involved
at all. I only know things have been working smoothly. From what I knew,
which was far from knowing in depth the MS development environment,
avoiding precompiled headers was always preferred.

Then, when VS2005 Beta came along, "troubles" started. Some suggested
me to put the statement #undef UNICODE before the #include "stdafx.h"
(due to changes in VS2005 towards the default of using UNICODE) and
that worked too, still without using precompiled headers.

It seems from your description that they went farther along toward
organizing
the UNICODE option (possibly mandatory? or at least pushing toward that
direction) which makes sense.

I will give it a shot later today and respond the results here again.

Thanks,

David

>
> > I also recalled that the "NOT using precompiled header files" was not
> > by default but as Mark wrote, by me checking off a respective box
> > during
> > the new project setup dialogs. But the bottom line is that I am not
> > using precompiled header files.
> >
> > I also recalled that in the beta version, I had to include the
> > statement #undef UNICODE
> > before the #include "stdafx.h" (thanks to a tip someone gave me here)
> > but it did not help now even though I added it.
>
> Anything that precedes
>
> #include "stdafx.h"
>
> is ignored. If you have a preprocessor command that needs to precede the
> inclusion of windows.h, for example, the place to put it is *inside* the
> stdafx.h file.
>
> >> The easy solution: Start a new project. Make sure it is the kind of
> >> project you want for your program. This will give you the proper
> >> default build settings, and a proper stdafx.h file. Then copy and
> >> paste your code into the new project.
> >
> > I have tried that twice (with two different source files that worked
> > under the VS2005 Beta version) and it did not help.
> > I noticed by searching the microsoft website that there is a ton of
> > complains on that very problem but could not find a respond there
> > that address the root cause of the problem.
> >
> > Have you actually tried to produce an elementary Win32 Console
> > Application that has the #include "stdafx.h" statement and
> > found it to be working with no problem under the VS 2005 Pro
> > released version?
>
> Here is what I do in VS2005 Team System (I presume it is the same as
VS2005
> Pro):
>
> From the menu choose
>
> File->New->Project
>
> then select
>
> Visual C++ ->Win32
>
> under Project Types (left window) and
>
> Win32 Console Application
>
> under Templates (right window)
>
> Enter the project name in the field in the bottom section of the dialog
and
> enter the location where the project is to be created, then click OK.
>
> At the next screen, choose Application Settings on the left and ensure
that
>
> Precompiled header
>
> is checked. Then click Finish. This produces three files for me, which I
> reproduce below:
>
>
>
////////////////////////////////////////////////////////////////////////////
//////////
> // stdafx.h : include file for standard system include files,
> // or project specific include files that are used frequently, but
> // are changed infrequently
> //
>
> #pragma once
>
> #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from
> Windows headers
> #include <stdio.h>
> #include <tchar.h>
>
> // TODO: reference additional headers your program requires here
>
>
////////////////////////////////////////////////////////////////////////////
///////////
>
>
>
>
////////////////////////////////////////////////////////////////////////////
/
> // stdafx.cpp : source file that includes just the standard includes
> // ProjectName.pch will be the pre-compiled header
> // stdafx.obj will contain the pre-compiled type information
>
> #include "stdafx.h"
>
> // TODO: reference any additional headers you need in STDAFX.H
> // and not in this file
>
>
////////////////////////////////////////////////////////////////////////////
/////////
>
>
> /////////////////////////////////////////////////////////////////////////
> // ProjectName.cpp : Defines the entry point for the console application.
> //
>
> #include "stdafx.h"
>
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> return 0;
> }
>
////////////////////////////////////////////////////////////////////////////
>
> --
> John Carson
>
>
>
>


.



Relevant Pages

  • Re: Seeting malloc pointer to NULL [2] -Totally confused!!!!!
    ... unexpected end of file while looking for precompiled header ... Those won't be available on your MCU compiler anyway, ... using namespace System; ... contains will also be available there, be ready for missing functionality. ...
    (microsoft.public.vc.language)
  • Re: VC2005 Pro: IDE (Compiler ?) cant find Stdafx.h
    ... >> words you told the compiler to include a file that does not exist. ... > "stdafx.h" statement in my source files. ... A precompiled header has a .pch extension. ... under Templates (right window) ...
    (microsoft.public.vc.language)
  • Re: VC2005 Pro: IDE (Compiler ?) cant find Stdafx.h
    ... That is the file that the compiler produces. ... >> stdafx.h+.cpp as well as some other resource files, ... empty project has to be unchecked and ...
    (microsoft.public.vc.language)
  • Re: Interesting #define #ifdef behavior
    ... header, or any of the headers that are included in the precompiled header, ... would mean using the precompiled header feature could cause problems ... PCH is included, the compiler takes the PCH as-is and takes it from there. ...
    (microsoft.public.vc.language)
  • Re: security issues with forth
    ... I assume she does not mean that the compiler actually corrects the errors, ... hInstance = GetModuleHandle; ... if (!aRegister) { ... If the window failed to register, ...
    (comp.lang.forth)