4
votes

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.

5
Did you forget to add '#include "stdafx.h"' to your source?Jepessen
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 somewhereYePhIcK
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.Hans Passant
Jepessen, I don't want to use the precompiled headers. That's why I turned them off.Void Chicken
Thanks Hans. I only disabled it in one configuration.Void Chicken

5 Answers

5
votes

Ok. Hans Passant found out what was happening:

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

3
votes

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).

2
votes

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.

0
votes

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
votes

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.