问题
Dear All I have a small Fortran program containing preprocessor macro. Below is a minimal example. On mac os x, it works well but when I compile it on windows 7 (64-bit) it always prints unknown operating system
. I am using gfortran-4.8.0 (mingw32) on windows 7.
program foo
implicit integer(i-n), double precision (a-h,o-p),
+ character*8(x-z)
*
#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 will be appreciated.
回答1:
This might 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 your build process generate a file with these builtin macro definitions which you can then include. E.g. have a make target which runs
gcc -E -dM - < /dev/null > builtins.inc
Then your sources should depend on builtins.inc in the Makefile, and in the beginning of your source files you
#include "builtins.inc"
来源:https://stackoverflow.com/questions/23856859/preprocessor-macro-not-working-on-windows-in-fortran-code