C++ 如何停止 IntelliSense PCH 警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19215981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I stop an IntelliSense PCH Warning?
提问by NobleUplift
A few of my header files have no includes, so I receive this message in Visual Studio 2010:
我的一些头文件没有包含,所以我在 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>
它消失了。如何在不添加(可能未使用)的情况下阻止此错误显示>
采纳答案by tatigo
When adding a .cpp file it inherits the PCH settings of the project. More detailed explanation of the problem here
添加 .cpp 文件时,它会继承项目的 PCH 设置。更详细的问题解释here
Solutions:
解决方案:
- Add
#pragma once
at the start of the file.
#pragma once
在文件开头添加。
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
它会导致你的源文件在一次编译中只包含一次,因此编译器会满意并且不需要额外的 #include
- Setting your project to not use precompiled headers
- Disable PCH usage for that one cpp file you've added, which will clear both IntelliSense and compiler warning/error.
- 将您的项目设置为不使用预编译头文件
- 为您添加的那个 cpp 文件禁用 PCH 使用,这将清除 IntelliSense 和编译器警告/错误。
Note! I'm including num 2, and 3 because some say it helped, but it only num 1 that did solve my case.
笔记!我包括 num 2 和 3,因为有人说它有帮助,但只有 num 1 确实解决了我的问题。
回答by Serid
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
我想问题是您的项目中有预编译的头文件(默认情况下为“stdafx.h”)并且要正确解决您应该添加的问题
#include "stdafx.h"
at start of your header/source file.
在头文件/源文件的开头。