Generate list of preprocessor macros defined by the compiler
-
30-04-2021 - |
Question
With gcc and gfortran I can generate a list of preprossesor macros defined by the compiler using (edited to reflect ouah's answer)
gcc -E -dM - < /dev/null
and
gfortran -cpp -E -dM /dev/null
respectively (on Linux at least).
How can I do the same with the Intel compilers icc and ifort? I know that for ifort these macros are defined here, but I would like to be able to generate this list myself, since the exact macros in use and their values will depend on the compiler options used. I am also aware of the predef project.
Solution 2
With the Intel Fortran compiler, ifort, the following can be used:
ifort -E -fpp /dev/null -dryrun 2>&1 | grep -e -D | cut -c 5-
It seems than ifort does not have an equivalent -dM
flag like icc, gfortran and gcc do.
OTHER TIPS
Use this with the Intel compiler:
icc -E -dM - < /dev/null
Note that with gcc
, the -E
option is also required if you want to use the -dM
preprocessor option.
For gfortran
, beware that gfortran -E -dM - < /dev/null
yields the same result as if you had called gcc
, which probably isn't helpful. You probably want something like this (source):
gfortran -cpp -E -dM empty.f
That will give you a smaller list of what gfortran
actually predefines. You will note that the results most likely do not include anything helpful for determining the operating system. Generally, for Fortran, you're left to define those yourself. See here for additional detail. You could also try something like this, but I'm a little skeptical of the practically of that solution. Also, that link implies that at one time gfortran
defined more than it does now.