A non-Windows preprocessor macro processor in Fortran code

Dear All, I have a small Fortran program containing a preprocessor macro. Below is a minimal example. It works fine on mac os x, but when I compile it on Windows 7 (64-bit), it always prints an unknown operating system . I am using gfortran-4.8.0 (mingw32) for Windows 7.

  program foo implicit integer(in), double precision (ah,op), + character*8(xz) * #ifdef _WIN64 zterm = 'wxt' #elif _WIN32 zterm = 'wxt' #elif __APPLE__ zterm = 'aqua' #elif __linux zterm = 'x11' #elif __unix zterm = 'x11' #elif __posix zterm = 'x11' #else print*, 'unknown operating system' #endif end program foo 

Changing #ifdef _WIN64 to #if defined (_WIN64) did not help. Any suggestion would be appreciated.

0
macros fortran gfortran
source share
1 answer

It could be GFortran PR 42954 . Since GFortran started using libcpp instead of running cpp in a separate process, many of these built-in macros are missing.

As a workaround, you can, as part of the build process, generate a file with these built-in macro definitions, which you can then include. For example. there is a make target that runs

 gcc -E -dM - < /dev/null > builtins.inc 

Then your sources should depend on builtins.inc in the Makefile, and at the beginning of your source files you

 #include "builtins.inc" 
+1
source share

All Articles