5

I'm trying to create a C++ static library in Visual Studio Express 2013 for Windows Desktop (v12.0.30723.00 Update 3). I don't want to use precompiled headers in my library. I can't get the most basic project to compile without errors.

The problem can be easily duplicated as follows:

  1. File->New Project
  2. Select Templates->Visual C++->CLR->Class Library. Click OK to create ClassLibrary1 in the default location.
  3. In Project->Properties, go to Configuration Properties->C/C++->Precompiled Headers, and set the Precompiled Header option to "Not Using Precompiled Headers".
  4. Edit the files AssemblyInfo.cpp and ClassLibrary1.cpp, and comment out the #include "stdafx.h" at the top of each file.
  5. In the Solution Explorer, right-click on Stdafx.cpp and select "Exclude from Project".
  6. Rebuild the solution.

I get the following two errors:

1   error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?   AssemblyInfo.cpp   39   1   ClassLibrary1
2   error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?   ClassLibrary1.cpp   7   1   ClassLibrary1

Am I missing a step, or have I found a bug in this version of Visual Studio?

sifferman
  • 2,955
  • 2
  • 27
  • 37
  • 1
    I tried this in Visual Studio 2013 Ultimate and I cannot reproduce this issue. I have some questions: 1. Are you sure that you saved the Project file (Changing Project Properties and clicking "OK" does not save the vcxproj file, you must click "Save All" in the File menu after clicking OK)? 2. Are you building the same Solution Configuration that you changed the Precompiled Header settings for? – Dai Dec 06 '14 at 04:07
  • You nailed it. The Active configuration was Debug, but it seems I was changing the property for the Release configuration. Thanks! – sifferman Dec 06 '14 at 04:15

2 Answers2

13

Sometimes you can spend hours scratching your head over something that has a very basic solution. In this case, the Active configuration was Debug, but I was changing the Precompiled Header option for the Release configuration. When I changed the option in the Debug configuration, voila! no more errors.

sifferman
  • 2,955
  • 2
  • 27
  • 37
  • Brilliant! Thanks for saving me scratching my head for hours and just reducing it to an embarrassingly large number of minutes. LMAO ;-) – Captain Normal Oct 02 '20 at 16:10
  • 2
    You're lucky :) I've switched off PCH for all configurations and the problem won't go away. – sigfpe Feb 25 '21 at 22:55
0

If the problem is not the configuration, it is very likely that you have enabled pre-compiled headers for a single file in your project. This happens in particular, if you have a stdafx.cpp file created by Visual Studio. See the answer by selbie in this post:

C++ Precompiled Header Disabled

user74696c
  • 324
  • 4
  • 12