How do I stop an IntelliSense PCH Warning?
Asked Answered
D

5

25

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>

Discontinuous answered 7/10, 2013 at 1:45 Comment(0)
W
24

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.

Wilsonwilt answered 10/3, 2014 at 14:11 Comment(8)
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.Discontinuous
Only took me half a year, but I finally accepted your answer! :DDiscontinuous
can you please explain #pragma directive ?! why it solves the problem ?Preexist
@GokulJai you can see what it means in here: en.wikipedia.org/wiki/Pragma_once and a discussion about its benifits in here: #1144436Doublet
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).Laborsaving
I already had #pragma once in my file. Maybe you should explain what causes this error, rather than a single potential solution to it.Townes
@Nic Hartley, try to setting your project to not use precompiled headers. As for explanation: connect.microsoft.com/VisualStudio/feedback/details/650359/…Wilsonwilt
Updated the answer to provide possible problem explanation and solutionsWilsonwilt
P
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.

Pachton answered 6/1, 2017 at 11:24 Comment(2)
Well, I think he should have fixed his problem more than 3 years ago now. ;)Penuche
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.Pachton
O
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

Orit answered 6/11, 2018 at 23:3 Comment(1)
or also add #include "pch.h" in the beginning of your fileFedak
A
2

Restart Visual Studio (close all active projects).

Nothing helped me except this

Anthropogenesis answered 9/5, 2021 at 18:33 Comment(1)
Better as a commentSarsen
K
0

Closing the solution and deleting the .vs folder below the solution folder can often fix the problem. The .vs folder contains the intellisense database for the solution. Vs will be rebuild it the next time the solution is opened.

Kikelia answered 3/8, 2024 at 20:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.