如何从预处理器宏识别平台/编译器? [英] How to identify platform/compiler from preprocessor macros?
问题描述
我编写一个跨平台代码,应该在linux,windows,Mac OS上编译。在Windows上,我必须支持visual studio和mingw。
有一些平台特定的代码,我应该放在 #ifdef。 。#endif
环境。例如,这里我放置了win32的具体代码:
#ifdef WIN32
#include< windows.h>
#endif
但是如何识别linux和mac操作系统? :: : / p>
#ifdef __APPLE__
在Windows上 MingW :
#ifdef __MINGW32__
Linux :
#ifdef __linux__
对于其他Windows编译器,请选中此主题和此适用于其他几个编译器和体系结构。
I'm writing a cross-platform code, which should compile at linux, windows, Mac OS. On windows, I must support visual studio and mingw.
There are some pieces of platform-specific code, which I should place in #ifdef .. #endif
environment. For example, here I placed win32 specific code:
#ifdef WIN32
#include <windows.h>
#endif
But how do I recognize linux and mac OS? What are defines names (or etc.) I should use?
For Mac OS:
#ifdef __APPLE__
For MingW on Windows:
#ifdef __MINGW32__
For Linux:
#ifdef __linux__
For other Windows compilers, check this thread and this for several other compilers and architectures.
这篇关于如何从预处理器宏识别平台/编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!