A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://stackoverflow.com/questions/259248/how-do-i-test-the-current-version-of-gcc below:

c++ - How to test the current version of GCC at compile time?

I would like to include a different file depending on the version of GCC. More precisely I want to write:

#if GCC_VERSION >= 4.2
#  include <unordered_map>
#  define EXT std
#elif GCC_VERSION >= 4
#  include <tr1/unordered_map>
#  define EXT std
#else
#  include <ext/hash_map>
#  define unordered_map __gnu_cxx::hash_map
#  define EXT __gnu_cxx
#endif

I don't care about gcc before 3.2.

I am pretty sure there is a variable defined at preprocessing time for that, I just can't find it again.

asked Nov 3, 2008 at 16:50

PierreBdRPierreBdR

43.5k1010 gold badges4848 silver badges6666 bronze badges

There are a number of macros that should be defined for your needs:

__GNUC__              // major
__GNUC_MINOR__        // minor
__GNUC_PATCHLEVEL__   // patch

The version format is major.minor.patch, e.g. 4.0.2

The documentation for these can be found here.

answered Nov 3, 2008 at 16:59

lukeluke

37.6k88 gold badges6161 silver badges8282 bronze badges

Ok, after more searches, it one possible way of doing it is using __GNUC_PREREQ defined in features.h.

#ifdef __GNUC__
#  include <features.h>
#  if __GNUC_PREREQ(4,0)
//      If  gcc_version >= 4.0
#  elif __GNUC_PREREQ(3,2)
//       If gcc_version >= 3.2
#  else
//       Else
#  endif
#else
//    If not gcc
#endif

answered Nov 3, 2008 at 16:59

PierreBdRPierreBdR

43.5k1010 gold badges4848 silver badges6666 bronze badges

5

As a side note:

To find all the predefined macros:

4

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4