C++跨平台预定义宏


x

Macro Definition
__linux__ Linux and Linux-derived
__ANDROID__ Android
#if defined(__linux__) && !defined(__ANDROID__) Linux (non-Android)
__APPLE__ Darwin (macOS and iOS)
_WIN32 Windows (32- and 64-bit)
_WIN64 Windows 64-bit
_MSC_VER Visual Studio
__GNUC__ gcc
__clang__ clang
__EMSCRIPTEN__ emscripten
__MINGW32__ MinGW 32, MinGW-w64 32-bit
__MINGW64__ MinGW-w64 64-bit
ARM9 (1) Nintendo DS (ARM9)
_3DS (1) Nintendo 3DS
__SWITCH__ (1) Nintendo Switch

相关参考

Common Predefined Macros (The C Preprocessor) (gnu.org)

Predefined Macros (The C Preprocessor) (gnu.org)

Guide to predefined macros in C++ compilers (gcc, clang, msvc etc.) (kowalczyk.info)

Predefined C/C++ macros for cross-platform development - DEV Community

c++ - How to identify platform/compiler from preprocessor macros? - Stack Overflow

c++ - How to detect reliably Mac OS X, iOS, Linux, Windows in C preprocessor? - Stack Overflow

Predefined macros | Microsoft Docs

CPP / C++ - Preprocessor and Macros (caiorss.github.io)

Pre-defined Compiler Macros / Wiki / Libraries (sourceforge.net)

Replacing text macros - cppreference.com