繁体   English   中英

包含带有 ifdef 的标头

[英]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 一起使用?

不幸的是,您不能使用预编译的标头和使用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(
//https://stackoverflow.com/a/36271896/6160632

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM