skipped when looking for precompiled header

74,095

Solution 1

Did you read the error message?

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

I don't see an #include "stdafx.h" in enginuity.cpp. ;) If you're using precompiled headers, you need to include the precompiled header in every source (.cpp) file.

Solution 2

I just experienced this error when including stdafx.h in a cpp file located in a parent folder above where stdafx.h is.

#include "subfolder\stdafx.h"

causes the compile error. Changing it to:

#include "stdafx.h"

fixes the compile error, but then intellisense freaks out.

The "fix" for intellisense, according to someone at Microsoft here, is to add "$(ProjectDir)" (or wherever the stdafx.h is) to the list of directories under Project->Properties->Configuration Propertes->C/C++->General->Additional Include Directories.

I've verified this works in Visual Studio 2012. Should work in 2010 as well.

Solution 3

You'll either want to put the line

#include "stdafx.h"

at the top of all your .cpp files (in this case, enenuity.cpp is the only one missing it.

or disable precompiled headers in your project.

If you have precompiled headers enabled in your project, Visual C++ will look for that #include directive at the top of all your source files. If it's not there, you'll get the negative commentary you received.

Solution 4

IF APPROVED SOLUTION DOES NOT WORK FOR YOU:

In my case the stdafx.h include was after other includes in my .cpp file.

Setting the #include "stdafx.h" statement at the TOP of the .cpp file fixed my errors.

Solution 5

It is possible to disable precompiled headers for a single file (VS2010). Select the .cc or .cpp file that is causing the annoyance, right mouse menu, properties, precompiled headers , Precompiled Header (change to) Not Using Precompiled Headers.

Share:
74,095
numerical25
Author by

numerical25

Updated on July 05, 2022

Comments

  • numerical25
    numerical25 almost 2 years

    So some reason, my .cpp file is missing it's header file. But I am not including the header file anywhere else. I just started so I checked all the files I made

    enginuity.h

    #ifndef _ENGINE_
    #define _ENGINE_
    
    class Enginuity
    {
    
    public:
        void InitWindow();
    
    };
    

    enginuity.cpp

    #include "Enginuity.h"
    
    
    void Enginuity::InitWindow()
    {
    
    }
    

    main.cpp

    #include "stdafx.h"
    #include "GameProject1.h"
    
    #define MAX_LOADSTRING 100
    
    // Global Variables:
    HINSTANCE hInst;                                // current instance
    TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
    
    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCE, int);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
    INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
    
    code.....
    #endif
    

    dont know what's going on. The error I get is

    1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(1) : warning C4627: '#include "Enginuity.h"': skipped when looking for precompiled header use
    1>        Add directive to 'stdafx.h' or rebuild precompiled header
    1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(8) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
    
  • Michael Mrozek
    Michael Mrozek almost 14 years
    Makes me miss being a teaching assistant. "I'm getting the error 'unexpected end of line; possible missing semicolon', what should I do?" "Well...are you missing a semicolon?" "Oh yeah!"
  • numerical25
    numerical25 almost 14 years
    I tried to add it in my header but I I still got the error. I didn't know it had to be in the .cpp file or even all .cpp files at that. I am getting confused about pre compiled headers. I thought that once a header is included in a file once. It can no longer included again???
  • Michael Mrozek
    Michael Mrozek almost 14 years
    @num It can be, although you usually don't want it to be. It's not included in enginuity.cpp though, just main.cpp
  • numerical25
    numerical25 almost 14 years
    Ok, so what about the pragma once. I thought that when that is implemented in a header, the header is only included the first time it's called ?? If I put stdafx.h in all my .cpp files. Wouldnt stdafx.h be ignored by all other files except for the first one that calls it??
  • JohnMcG
    JohnMcG almost 14 years
    The #include "stdafx.h" needs to be the very first thing in every .cpp file.
  • Michael Mrozek
    Michael Mrozek almost 14 years
    @num No, you can (and must) include it in every cpp file. The only thing #pragma once or header guards do is stop you from including a header twice in the same cpp file
  • Hugo Estrada
    Hugo Estrada almost 13 years
    Great, this solved a similar problem that I had, but the error that I was getting was for <string> and <iostream>
  • hfrmobile
    hfrmobile about 8 years
    Also works with Visual Studio 2013 Community Edition :)
  • andriy
    andriy over 6 years
    Still necessary in Visual Studio 2017 when the .cpp files are in subdirectories. Thanks for posting this answer!