为什么我无法#ifdef stdafx.h? [英] Why am I unable to #ifdef stdafx.h?
问题描述
我正在尝试在.cpp文件中包括2个特定于平台的 stdafx.h 文件,但是当我尝试#ifdef时,编译器并不满意.
I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it.
#ifdef _WIN32
#include "stdafx.h"
#elif _MAC
#include "MAC/stdafx.h"
#endif
您可能想知道为什么我在Mac代码中使用了stdafx.h,但这并不重要:).
You may wonder why I am using stdafx.h in the Mac code, but that is not important at the moment :).
当我尝试在Windows上编译代码时,收到:致命错误C1018 .我尝试用#ifdef将其他头文件包含在同一文件中,并且编译器很满意.因此,似乎Windows不喜欢stdafx.h为#ifdef版本,或者Windows仅允许 #include stdafx.h 成为文件的第一行.
When I try to compile the code on Windows, I receive: Fatal Error C1018. I tried enclosing other header files with #ifdef in the same file, and the compiler was happy. Therefore, it looks like Windows doesn't like stdafx.h to be #ifdef-ed, or that Windows only allows #include stdafx.h to be the first line in the file.
所以我的问题是,为什么?
So my question is, why?
凯特
推荐答案
当编译器包含预编译的头文件时,它基本上忘记"了该头文件之前的所有内容.因此,您的#elif与#if不再匹配.
When the compiler includes a pre-compiled header, it basically "forgets" anything that came before the header. Thus your #elif isn't matched to a #if anymore.
这篇关于为什么我无法#ifdef stdafx.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!