Preprocessor Macro not working on Windows in Fortran Code

北战南征 提交于 2020-01-20 08:50:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!