如何在c++预处理器中检测到g++和MinGW ?

时间:2022-11-25 11:07:27

I want to do something like:

我想做的是:

#ifdef GCC
#define GetFunctionName() string("My function name is ") + __PRETTY_FUNCTION__;
#endif

Since I want to use pretty PRETTY_FUNCTION this is only supported by gnu as far as I know so I need to detect if I am compiling for g++ and MinGW, how can I do that? I'm guessing all I need to know are the compiler's preprocessor definitions, like I did for Microsoft below.

因为我想要使用漂亮的PRETTY_FUNCTION,我知道gnu只支持这个功能,所以我需要检测我是否在为g++和MinGW编译,我该怎么做呢?我想我只需要知道编译器的预处理器定义,就像我在下面为Microsoft所做的那样。

#ifdef WIN32
#define LogFuncBegin() gLogger.FuncBegin( __FUNCTION__ );
#define LogFuncEndSuccess() gLogger.FuncEndSuccess( __FUNCTION__ );
#endif

How can I detect g++ and MinGW in C++ preprocessor?

如何在c++预处理器中检测到g++和MinGW ?

2 个解决方案

#1


38  

You can make use of:

你可以使用:

#ifdef __GNUC__
#ifdef __MINGW32__

For additional macro's you might be interested in this page which shows other compiler macros

对于其他宏,您可能会对显示其他编译器宏的页面感兴趣

#2


25  

For GCC:

GCC:

#ifdef __GNUC__

For MinGW:

MinGW:

#ifdef __MINGW32__

x86_64-w64-mingw32-gcc defines both __MINGW32__ and __MINGW64__.

x86_64-w64-mingw32-gcc同时定义了__MINGW32__和__MINGW64__。

#1


38  

You can make use of:

你可以使用:

#ifdef __GNUC__
#ifdef __MINGW32__

For additional macro's you might be interested in this page which shows other compiler macros

对于其他宏,您可能会对显示其他编译器宏的页面感兴趣

#2


25  

For GCC:

GCC:

#ifdef __GNUC__

For MinGW:

MinGW:

#ifdef __MINGW32__

x86_64-w64-mingw32-gcc defines both __MINGW32__ and __MINGW64__.

x86_64-w64-mingw32-gcc同时定义了__MINGW32__和__MINGW64__。