在stdafx.h之前不能包含任何标头 [英] Cannot include any header before stdafx.h

查看:94
本文介绍了在stdafx.h之前不能包含任何标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置并使用DLL并阅读有关如何操作的一些教程。

我想知道,为什么intellisense给了我 - 无法打开源文件Header.h - 错误。

奇怪的是,如果我要包含stdafx.h,那么在Header.h之前,错误就会消失,这里是标题的代码:



I'm trying to set up and use a DLL and read few tutorials on how to do it.
I'd like to know however, why the intellisense is giving me the -cannot open source file "Header.h"- error.
The strange thing is that if I were to include the stdafx.h BEFORE the said Header.h the error subsides, here's the header's code :

#ifndef INDLL_H
#define INDLL_H

#ifdef EXPORTING_DLL
extern __declspec(dllexport) int Triplica(int);
#else
extern __declspec(dllimport) int Triplica(int);
#endif

#endif





.cpp文件为空,除了include语句,我看到intellisense错误。

再次,警告消失我要在标题之前加入stdafx.h



这背后的魔力是什么?

我明白了预编译头的原因,但我仍然不能在我脑海中包裹为什么它必须在我的.cpp文件之上,我从来没有用其他win32项目做这个



.cpp file is empty, except for the include statement where I see the intellisense error.
Again, the warning goes away if I'm going to include stdafx.h before said header

What's the magic behind this ?
I do understand the reason for precompiled headers, but i still can't wrap in my head why it has to be on top of my .cpp file, I never had to do this with other win32 projects

推荐答案

请阅读以下主题:

http://en.wikipedia.org/wiki/Precompiled_header [ ^ ],

< a href =https://msdn.microsoft.com/en-us/library/3dxawkbx.aspx> https://msdn.microsoft.com/en-us/library/3dxawkbx.aspx [<一个href =https://msdn.microsoft.com/en-us/library/3dxawkbx.aspx\"target =_ blanktitle =New Window> ^ ]。



你的问题是预编译头文件的后果之一,但是,从你的代码示例中,我看不出你搞砸了哪里。只需彻底查看您的错误消息并应用您的逻辑。如果您无法解决问题,请提供全面的代码示例以及所有重要事项,但请尽量减少。这些问题很容易解决。



-SA
Just read on the topic:
http://en.wikipedia.org/wiki/Precompiled_header[^],
https://msdn.microsoft.com/en-us/library/3dxawkbx.aspx[^].

Your problem is one of the consequences of having precompiled headers, but, from your code sample, I cannot see where did you screw up. Just look at your error message thoroughly and apply your logic. If you cannot resolve it, please provide comprehensive code sample with all what matters, but please make it minimal. Such problems are resolved extremely easily.

—SA


这篇关于在stdafx.h之前不能包含任何标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆