22

A few of my header files have no includes, so I receive this message in Visual Studio 2010:

IntelliSense: PCH warning: cannot find a suitable header stop location.  An intellisense PCH file was not generated.

If I add a single header, for instance:

#include <iostream>

It disappears. How can I stop this error from showing without adding (potentially unused) include>

NobleUplift
  • 4,577
  • 6
  • 37
  • 76

4 Answers4

21

When adding a .cpp file it inherits the PCH settings of the project. More detailed explanation of the problem here

Solutions:

  1. Add #pragma once at the start of the file.

It will cause your source file to be included only once in a single compilation, therefore the compiler will be satisfied and won't require additional #include

  1. Setting your project to not use precompiled headers
  2. Disable PCH usage for that one cpp file you've added, which will clear both IntelliSense and compiler warning/error.

Note! I'm including num 2, and 3 because some say it helped, but it only num 1 that did solve my case.

tatigo
  • 1,874
  • 1
  • 25
  • 30
  • I... don't even remember what project of mine this error is from. I'll just open every one in VS2010 until I receive this error and can try `#pragma once`. – NobleUplift Mar 11 '14 at 15:13
  • Only took me half a year, but I finally accepted your answer! :D – NobleUplift Sep 04 '14 at 14:24
  • 1
    can you please explain #pragma directive ?! why it solves the problem ? – Gokul E Dec 05 '14 at 07:21
  • 2
    @GokulJai you can see what it means in here: http://en.wikipedia.org/wiki/Pragma_once and a discussion about its benifits in here: http://stackoverflow.com/questions/1143936/pragma-once-vs-include-guards – Ravid Goldenberg Dec 05 '14 at 10:09
  • 1
    Maybe this helps for headers, but it doesn't make sense to add this in a .c/.cpp file (nor does it resolve the error in such a case). Restarting VS did the trick for me (rebuilding and restarting the C++ IntelliSense parser service wasn't enough). – Cameron Feb 05 '16 at 22:23
  • I already had `#pragma once` in my file. Maybe you should explain what causes this error, rather than a single potential solution to it. – Fund Monica's Lawsuit Jan 25 '18 at 02:38
  • @Nic Hartley, try to setting your project to not use precompiled headers. As for explanation: https://connect.microsoft.com/VisualStudio/feedback/details/650359/intellisense-pch-warning-can-not-find-a-suitable-header-stop-location-a-pch-file-wasnt-generated – tatigo Jan 25 '18 at 05:10
  • Updated the answer to provide possible problem explanation and solutions – tatigo Jan 25 '18 at 05:23
6

I suppose the problem is that you have precompiled header in your project (by default "stdafx.h") and to correctly solve the problem you should add

#include "stdafx.h"

at start of your header/source file.

Serid
  • 307
  • 5
  • 12
  • Well, I think he should have fixed his problem more than 3 years ago now. ;) – Eiko Jan 06 '17 at 11:48
  • 2
    I wrote this asnwer for other users who encounter this problem to know why this problem occurs. F.E. I had the same problem, I visited this question saw an anser that solves the problem, but I didnt know why it does, so I thinked and wrote another answer that also soves problem AND explains how it solves it. – Serid Jan 26 '17 at 16:43
3

Go to project's property and under C/C++ => Precompiled Headers, find the option "Precompiled header".

Change it to "Not Using Precompiled Headers".

enter image description here

Natasha
  • 5,685
  • 1
  • 27
  • 47
0

Restart Visual Studio (close all active projects).

Nothing helped me except this

Lio Ak
  • 21
  • 1