1

My app is working correctly, but I'm trying to clear up something. When I include the precompile header in my source files, I get the following happen.

WTF

Basically the first line is underlined as if there is a problem with it, so I have to include it again underneath, with the correct path... but I need both or it wont compile.

Any ideas?

Nick
  • 1,015
  • 12
  • 31
  • 1
    Are you saying that if you remove the first, it doesn't compile? Could you please add to the question the specific text of the error showing up? Also, are you aware of https://stackoverflow.com/a/26330290/4944425 ? – Bob__ Nov 01 '17 at 15:27
  • 3
    There must be only *one* precompiled header file and all source files in the project have to agree about which one it is. So pretty high odds that the first one isn't being used at all and that you got a warning about it, one that programmers often don't see for some reason. Improve your question by telling us what you see. – Hans Passant Nov 01 '17 at 15:30
  • You probably have 2 files... one at proper location for precompiled headers and another elsewhere with correct content. – Phil1970 Nov 01 '17 at 16:16
  • Hey guys, I'll check in the morning, just to be clear both lines are needed or it doesn't compile. So I can't remove either at the moment, I'll double check that there's only one file as suggested and get back to you tomorrow. – Nick Nov 01 '17 at 21:21
  • Generally in my experience (VS-) precompiled headers are a source of problems - I stopped using them long time ago. If you really need to speed up your compilation, try to use something else - e.g. tools like IncrediBuild... . – Trantor Nov 06 '17 at 13:33
  • Cheers, I'll take a look into that. – Nick Nov 06 '17 at 13:35

1 Answers1

4

The Visual Studio uses precompiled header only if the name matches (the name is not case-sensitive). Let say, a precompiled header name StdAfx.h is set in your project, so only when a code contains #include "stdafx.h" then is precompiled header used.

The #include "..\stdafx.h" is not recognized as the precompiled header even though it is the real location.

You need to add an include path to the location of stdafx.h into your project settings and then the header #include "stdafx.h" will be work correctly.

Another common issue with a precompiled header is that the include directive is in a header. It should be always in the source file (.ccp).

frido
  • 789
  • 5
  • 14
  • You are wrong about latter. `#include` can be used is other header files seamlessly. Just look into Standart Library headers to check it out. – Semyon Burov Nov 04 '17 at 14:40
  • Still not bad chance to check, will do during the week hopefully, but that sounds promising. Thanks. – Nick Nov 04 '17 at 18:33
  • 1
    @SemyonBurov, Imagine that `#include "stdafx.h"` is in a header of some library. It works seamlessly when compiling the library, but when compiling a project, which uses that library, then the precompiled header from the project is used. Now it won't compile unless your project precompiled header contains all that library needs. Now, it doesn't sound seamless. – frido Nov 05 '17 at 17:40
  • This worked, for some reason I had to include the root of the project as an include directory, isn't it an include directory by default? Anyway, upon doing this, problem goes away. – Nick Nov 06 '17 at 10:59
  • Sorry, would have given the bounty sooner if I knew I had to press that icon! lol – Nick Nov 08 '17 at 16:12