5

In Visual Studio 2015, I have a C++/CLI project with the following error:

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

I turned off precompiled headers in the project options but it keeps giving me the same error. I even removed the name of the precompiled header file but it still says "stdafx.h".

Edit: Yes, every source file indivuduially doesn't have it enabled.

6
  • 2
    Did you forget to add '#include "stdafx.h"' to your source?
    – Jepessen
    Nov 21, 2015 at 22:40
  • Try to "clean" your project and then build again. If you have really removed the precompiled headers this should work. Otherwise chances are you still have that enabled somewhere
    – YePhIcK
    Nov 21, 2015 at 22:43
  • 5
    In VS2015, you need hawkeyes to pay attention to the selected Configuration and Platform in the settings dialog. The two comboboxes at the top. They are often wrong and don't match your current selection so you'd be changing the wrong setting. Very crappy bug, I've lost at least two dozen gray hairs on it. Nov 21, 2015 at 23:05
  • 1
    Jepessen, I don't want to use the precompiled headers. That's why I turned them off. Nov 21, 2015 at 23:45
  • Thanks Hans. I only disabled it in one configuration. Nov 21, 2015 at 23:46

5 Answers 5

5

Ok. Hans Passant found out what was happening:

The build configuration that I used to build it still had precompiled headers enabled.

4

I met the same problem (turned off precompiled in project properties but the error remains).

Solution: open .proj file with any text editor and search for

<PrecompiledHeader>Use</PrecompiledHeader>

you will see that there are still some properties set to use it. Just replace word "Use" with "NotUsing" and problem fixed.

3

You may have disabled it for the project, but each individual source file can have it's own specific compiler settings. It's also possible you disabled pre-compiled headers for a specific source file, erroneously mistaking that action for a project wide setting.

For each individual C/C++ file in Solution Explorer, right click on it and select "Properties". Under C/C++ -> Precompiled Headers, make sure the Precompiled Header setting is "Not using Precompiled Headers".

The right click on your Project name in Solution Explorer and select "Properties as well" Double-check that the project settings are the same.

And if there's a stdafx.cpp file, it likely has the "Create Precompiled Header" setting. You can typically remove this file if it doesn't have any relevant code in it.

Repeat all the same steps for each Solutions configuration (e.g. both Debug and Release).

1
  • For most people this answer is more useful than the accepted answer.
    – user74696c
    Jun 17, 2021 at 10:42
0

Microsoft Visual Studio 2015:

Right click on solution -> Configuration Properties -> C/C++ -> Precompiled Headers -> Precompiled Header => Not Using Precompiled Headers

enter image description here

0

In my case, I found the pch.h still set in: c++ -> advanced -> forced include files.

Anyhow, Andrew's solution is still the best. Just open the proj. file in a text editor and ctrl-f search for the filename causing the issue. Much easier than skimming through all the properties in vs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.