不同Fortran预处理器的相对包含路径

问题描述 投票:0回答:0

考虑以下目录树:

test.F90
test/
├─ a.inc
└─ b.inc

文件内容如下:

  • test.F90
#include "test/a.inc"
end
  • a.inc
#if defined(__GFORTRAN__) | defined(__PGI) | defined(__NVCOMPILER)
#  include "b.inc"
#else
#  include "test/b.inc"
#endif

#include "b.inc"
#include "b.inc"
  • b.inc
print*,'!'

GNU (gfortran 11.1.0) 和 Nvidia (nvfortran 22.9) 编译器预处理器搜索要包含在相对于当前文件的目录中的文件。例如。

b.inc
应包含在
a.inc
#include "b.inc"
内。

Intel (ifort 2021.8.0, ifx 2023.0.0) 和 NAG (nagfor 7.1) 编译器预处理器搜索要包含在相对于第一个文件的目录中的文件以调用

include
。例如。
b.inc
应该包含在
a.inc
#include "test/b.inc"
内,因为
a.inc
包含在
test.F90
中。但是,它仅适用于第一个
include
命令。在所有后续的
include
命令中,目录被“更改”为
test
并且可以使用
#include "b.inc"
。虽然多个
#include "test/b.inc"
命令也可以在 Intel 编译器中运行,但如果将后续路径更改为
test/b.inc
.

,代码将无法使用 NAG 编译器进行编译

这是英特尔和 NAG 编译器预处理器的预期行为吗?有没有办法使

include
命令的行为独立于使用的编译器(并避免
a.inc
中的前 5 行)?

fortran preprocessor intel-fortran nag-fortran
© www.soinside.com 2019 - 2024. All rights reserved.