Why am I unable to #ifdef stdafx.h?

怎甘沉沦 提交于 2019-12-09 03:34:16

问题


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

You may wonder why I am using stdafx.h in the Mac code, but that is not important at the moment :).

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?

Kat


回答1:


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.




回答2:


This is because you have Precompiled Headers turned on - turn it off and you should be fine.



来源:https://stackoverflow.com/questions/1435804/why-am-i-unable-to-ifdef-stdafx-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!