1

Is there a good way to check the (gcc) compiler configuration at compile time (either from within a Makefile or from within a C source file). I want to check if the compiler being used has sufficient support for the code being compiled, and if not, I want it to fail immediately with a clear message asking the user to upgrade their toolchain.

Thanks

John

John
  • 3,400
  • 3
  • 31
  • 47

2 Answers2

0

The most used tools that I would recommend are autotools and CMake.

Autotools are the historical tools for the GNU projects and are a suite of scripts that allow the developer to implement feature detection via M4 scripting (autoconf). There are predefined macros for common tests.

CMake is a more recent native C++ toolchain that also include support for the most common features checks, and allows the developer to implement their own tests via its powerful language.

Be careful that both are complete build toolchains that completely replace hand-written makefiles. I believe however that the advantages they provide in terms of cross-platform support and maintainability is worth much more than the level of control provided by makefiles.

SirDarius
  • 41,440
  • 8
  • 86
  • 100
0

If the solution of the detected issues is upgrading the toolchain, then check __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ macros that are predefined by the compiler.

chill
  • 16,470
  • 2
  • 40
  • 44
  • I'm not looking for the toolchain version, but rather the configuration (use of posix threads, etc). – John Nov 21 '12 at 18:06