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

Solution 1:

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

Solution 2:

For GCC:

#ifdef __GNUC__

For MinGW:

#ifdef __MINGW32__

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