从 Fortran 中的 Makefile 确定变量
Determine variable from Makefile in Fortran
我想将我的数据与 !DIR$ ATTRIBUTES ALIGN:NBYTE::X
对齐,其中 NBYTE
是在编译时定义的。
我目前在每个源文件的顶部都有
#ifndef NBYTE
#define NBYTE 64
#endif
但是,如果我只能在所有地方使用 NBYTE
变量时定义它,我就不会这样做。
所以我的两个问题是:
是否可以仅定义一次宏并在所有地方使用它而不在每个源文件中包含一个文件或宏?
我可以在 Makefile 中定义变量并在我的 Fortran 代码中使用它吗?
大多数编译器允许您使用 C 类型预处理器对源代码进行预处理。同时,它们允许您通过编译器的命令行传递预处理器宏。在 gfortran
中,您可以使用以下语法:
-Dname=definition
: The contents of the definition are tokenized and processed as if they appeared during translation phase three in a #define
directive. In particular, the definition will be truncated by embedded newline characters.
我想将我的数据与 !DIR$ ATTRIBUTES ALIGN:NBYTE::X
对齐,其中 NBYTE
是在编译时定义的。
我目前在每个源文件的顶部都有
#ifndef NBYTE
#define NBYTE 64
#endif
但是,如果我只能在所有地方使用 NBYTE
变量时定义它,我就不会这样做。
所以我的两个问题是:
是否可以仅定义一次宏并在所有地方使用它而不在每个源文件中包含一个文件或宏?
我可以在 Makefile 中定义变量并在我的 Fortran 代码中使用它吗?
大多数编译器允许您使用 C 类型预处理器对源代码进行预处理。同时,它们允许您通过编译器的命令行传递预处理器宏。在 gfortran
中,您可以使用以下语法:
-Dname=definition
: The contents of the definition are tokenized and processed as if they appeared during translation phase three in a#define
directive. In particular, the definition will be truncated by embedded newline characters.