针对不同操作系统的Gfortran预处理器指令 [英] Gfortran pre-processor directives for Different Operating systems

查看:261
本文介绍了针对不同操作系统的Gfortran预处理器指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我,我该怎么做:

  #if __unix__ 
#define path_sep = '/'
#elif __windows__
#define path_sep ='\'
#else
#errorpath_sep not defined。
#endif

使用gfortran编译器。

解决方案

这可以结合条件编译并在命令行中使用D选项来完成。以下是一些示例代码:

 程序test_Dopt 
字符(len = 1):: pathsep
pathsep =?
#ifdef WOS
pathsep =\
#endif
#ifdef UOS
pathsep =/
#endif

write(*,'(pathsep is>,A1,<)')pathsep

end program test_Dopt
pre>

命名带有filetype F90的程序,以使gfortran运行预处理程序或在编译行中使用-cpp。然后通过将选项包含在D之后的编译行中,将选项传递给预处理器,例如gfortran -DWOS。 (这一点比gfortran更普遍 - 大多数Fortran编译器会处理C风格的预处理器指令。)然后,您可以在Fortran之外识别操作系统并将信息传递给Fortran程序。

您可以使用filetype F90或-cpp编译您的代码。

Could you tell me please how can I do the following:

#if __unix__
#define path_sep='/'
#elif __windows__
#define path_sep='\'
#else
#error "path_sep not defined."
#endif

using gfortran compiler.

解决方案

This can be done in combination with conditional compilation and using the "D" option on the command line. Here is some example code:

program test_Dopt
character (len=1) :: pathsep
pathsep = "?"
#ifdef WOS
   pathsep = "\"
#endif
#ifdef UOS
   pathsep = "/"
#endif

write (*, '( "pathsep is >", A1, "<")' )  pathsep

end program test_Dopt

Name the program with filetype F90 to cause gfortran to run the preprocessor or use -cpp on the compile line. Then pass options to the prepreprocessor by including them after D on the compile line, e.g., gfortran -DWOS. (This is more general then gfortran -- most Fortran compilers will process C-style pre-processor directives.) Then you can identify the OS outside of Fortran and pass the information to the Fortran program.

You can compile your code via using the filetype F90 or -cpp.

这篇关于针对不同操作系统的Gfortran预处理器指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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