使用 ifdef 包含 header
include of header with ifdef
我已尝试将以下内容放入我的 C++ 代码中:
#ifdef _WIN32
#include "stdafx.h"
#endif
但是我得到一个错误:
PCH warning: header stop cannot be in a macro of #if block. An IntelliSense PCH file was not generated.
我试图让我的代码在 windows 和 linux 上工作,stdafx.h 在 linux 上不起作用,而在 visual studio 上是必须的=].
还有其他方法可以使用 ifdef 包含吗?
不幸的是,您不能使用预编译 header 和 Microsoft MSVC 来做到这一点。 MSVC 完全忽略 #include "stdafx.h"
行之前的所有代码(以及任何垃圾)行。结果 #endif
将是它无法预料的。
将 #ifdef _WIN32
和不在 stdafx.h 内的内容放入。
我刚刚创建了一个空 stdafx.h。没有预编译头的解决方案的后续内容
#pragma once
//this is only for using Common modules with Precompiled headers. We can't disable it using a preprocessor(
//
我已尝试将以下内容放入我的 C++ 代码中:
#ifdef _WIN32
#include "stdafx.h"
#endif
但是我得到一个错误:
PCH warning: header stop cannot be in a macro of #if block. An IntelliSense PCH file was not generated.
我试图让我的代码在 windows 和 linux 上工作,stdafx.h 在 linux 上不起作用,而在 visual studio 上是必须的=].
还有其他方法可以使用 ifdef 包含吗?
不幸的是,您不能使用预编译 header 和 Microsoft MSVC 来做到这一点。 MSVC 完全忽略 #include "stdafx.h"
行之前的所有代码(以及任何垃圾)行。结果 #endif
将是它无法预料的。
将 #ifdef _WIN32
和不在 stdafx.h 内的内容放入。
我刚刚创建了一个空 stdafx.h。没有预编译头的解决方案的后续内容
#pragma once
//this is only for using Common modules with Precompiled headers. We can't disable it using a preprocessor(
//