Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect compiler with #ifdef

I'm trying to build a small code that works across multiple platforms and compilers. I use assertions, most of which can be turned off, but when compiling with PGI's pgicpp using -mp for OpenMP support, it automatically uses the --no_exceptions option: everywhere in my code with a "throw" statement generates a fatal compiler error. ("support for exception handling is disabled")

Is there a defined macro I can test to hide the throw statements on PGI? I usually work with gcc, which has GCC_VERSION and the like. I can't find any documentation describing these macros in PGI.

like image 641
Seth Johnson Avatar asked Aug 05 '09 13:08

Seth Johnson


People also ask

How do I know my compiler?

So if you ever need to check the version of the GCC C++ compiler that you have installed on your PC, you can do it through the command prompt by typing in the single line, g++ --version, and this will return the result.

What is the name of the compiler used to generate the EXE?

g++ command is a GNU c++ compiler invocation command, which is used for preprocessing, compilation, assembly and linking of source code to generate an executable file.


2 Answers

Take a look at the Pre-defined C/C++ Compiler Macros project on Sourceforge.

PGI's compiler has a __PGI macro.

Also, take a look at libnuwen's compiler.hh header for a decent way to 'normalize' compiler versioning macros.

like image 154
Michael Burr Avatar answered Oct 22 '22 03:10

Michael Burr


You could try this to see what macros are predefined by the compiler:

pgcc -dM

Maybe that will reveal a suitable macro you can use.

like image 20
Ville Laurikari Avatar answered Oct 22 '22 04:10

Ville Laurikari