0

I am trying to introduce precompiled headers into my project because of long compile times in my project right now. I have a main project that includes a main function and all the real code is in the DLL project(they are linked together.) I named my precompiled header "vpch.h" and i created a vpch.cpp that includes vpch.h. I am using visual studio 2017 so I went into the properties of vpch.cpp and selected Create. Then I added vpch.h as the first thing in all my cpp files. All files are set to use precompiled headers and reference vpch.h Every CPP files throws the error:

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

I am at a loss as to what to do because I have followed many tutorials and can't find a reason for this. As well as most issues that pop up on google are people just accidentally including precompiled headers.

My only thought is that maybe in the section in properties where it asks for the name of the precompiled header, I need to do more than put "vpch.h" and maybe an exact file location? Any help with this is super appreciated.

EDIT

From further debugging it would appear that all but ONE cpp file is throwing an error. The one that doesn't throw an error is the one that exists in the same exact folder as the vpch.h. So files that can't just write #include "vpch.h" and have to write something like "../vpch.h" I can write #include <vpch.h> and I am going to try that now but I am unsure that will help.

user3386109
  • 34,287
  • 7
  • 49
  • 68
Yea okay
  • 135
  • 8
  • If you want to use the Visual C++ precompiled header feature, why not let the project wizard create it for you and leave it as it is? And note that many large project disable it because it's often more trouble than it's worth. – Some programmer dude Nov 20 '19 at 18:37
  • @Someprogrammerdude I didn't use the wizard because I didn't need it in the beginning and didn't know how to use a wizard to re set it up. Also this has brought my compile time down from 20 seconds to 0.8 seconds so I believe this is something everyone should implement. Things like Windows.h, iostream, string, vector etc getting recompiled every single time is drastic in my opinion. – Yea okay Nov 20 '19 at 21:57

1 Answers1

0

The issue was with every CPP file that wasnt in the same folder as the precompiled header. So if you use a file structure that contains different classes in different folders, using #include "../../vpch.h" will actually fail. You must add the root folder to your additional include directories and then use #include <vpch.h> for all files. I can NOT tell you why using #include "../../vpch.h" wasn't working. It seems counter intuitive for it to fail in my opinion.

It may be because it searches for the precompiled header in the same folder as the file you are referencing it in. This answer, however, will work as a solution.

Yea okay
  • 135
  • 8
  • 1
    Use back ticks to highlight code. See my edit of the question. The problem is that brackets `<>` outside of code snippets are interpreted as an attempt to use HTML markup, and are ignored. – user3386109 Nov 20 '19 at 18:40