Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

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

like image 447
EddieV223 Avatar asked Jul 05 '13 17:07

EddieV223


People also ask

Is MinGW same as G ++?

The standard compiler releases since 4.6 include front ends for C (gcc), C++ (g++), Objective-C, Objective-C++, Fortran (gfortran), Java (gcj), Ada (GNAT), and Go (gccgo). MinGW stands for "Minimalist GNU for Windows" It is essentially a tool set that includes some GNU software, including a port of GCC.

What does the GCC preprocessor do?

The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command-line options.


2 Answers

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

like image 159
Floris Velleman Avatar answered Sep 26 '22 02:09

Floris Velleman


For GCC:

#ifdef __GNUC__ 

For MinGW:

#ifdef __MINGW32__ 

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

like image 32
sedavidw Avatar answered Sep 23 '22 02:09

sedavidw