【发布时间】:2016-06-03 05:44:54
【问题描述】:
我有跨平台(Windows 和 Linux)使用的代码。在 Windows 中,代码使用预编译的头文件,所以我包含 stdafx.h,但在 linux 中我没有。所以我在每个 .cpp 文件的顶部都有这个:
#ifdef WIN32
#include "stdafx.h"
#endif // WIN32 // compiler error here
这在 linux 上编译得很好,但在 Visual Studio 2013 中我得到编译器错误:
错误 2 错误 C1020:意外 #endif
我认为这是因为stdafx.h 包含一个#pragma once 宏。
我该如何解决这个问题,是否有更好的方法使代码跨平台?
【问题讨论】:
-
我不认为这是问题所在。
#ifdef WIN32 #pragma once #endif在这个 online VS compiler 中工作正常。 -
上述重复表明您的代码中有错字。
-
肯定直接的解决方案是不使用预编译的头文件?
标签: c++ visual-studio