预处理器宏在 Fortran 代码中的 Windows 上不起作用 [英] Preprocessor Macro not working on Windows in Fortran Code

查看:14
本文介绍了预处理器宏在 Fortran 代码中的 Windows 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我有一个包含预处理器宏的小型 Fortran 程序.下面是一个最小的例子.在 mac os x 上,它运行良好,但是当我在 windows 7(64 位)上编译它时,它总是打印 unknown operating system.我在 Windows 7 上使用 gfortran-4.8.0 (mingw32).

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

#ifdef _WIN64 更改为 #if defined (_WIN64) 没有帮助.任何建议将不胜感激.

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

推荐答案

这可能是 GFortran PR 42954.由于 GFortran 开始使用 libcpp 而不是在单独的进程中运行 cpp,因此缺少许多这些内置宏.

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.

作为一种解决方法,您可以在构建过程中生成一个包含这些内置宏定义的文件,然后您可以将其包含在内.例如.有一个运行的 make 目标

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

那么你的源代码应该依赖于 Makefile 中的 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"

这篇关于预处理器宏在 Fortran 代码中的 Windows 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆