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

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

问题描述

亲爱的我有一个包含预处理器宏的小型Fortran程序。下面是一个简单的例子。在Mac OS X上,它运行良好,但是当我在Windows 7(64位)上编译它时,它总是打印未知操作系统

 程序foo 
隐式整数(in)我在Windows 7上使用gfortran-4.8.0(mingw32) ,双精度(ah,op),
+字符* 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 *,'未知操作系统'
#endif
结束程序foo

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

解决方案

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



作为解决方法,您可以将其作为构建的一部分进程使用这些内置宏定义生成一个文件,然后可以包含这些宏定义。例如。有一个运行目标

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

然后,您的源代码应该依赖于Makefile中的builtins.inc,并且在开始时您的源文件您

  #includebuiltins.inc


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.

解决方案

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"

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

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