如何在makefile中定义一个变量,然后在Fortran代码中使用它 [英] How to define a variable in a makefile and then use it within Fortran code
本文介绍了如何在makefile中定义一个变量,然后在Fortran代码中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在makefile中定义一个变量,然后根据是否设置该变量,更改在我的Fortran例程中编译哪个代码块。
I am trying to define a variable in a makefile, and then depending on whether that variable is set, change which code block is compiled in my Fortran routine.
简单的例子我不能工作:
Simple example I can't get working:
program test
implicit none
integer :: a
#ifdef MYVAR
a = 1
#else
a = 0
#endif
write(*,*) a
end program test
我的makefile是:
My makefile is:
MYVAR=1
all:
ifort temp.F90 -fpp
echo $(MYVAR)
echo $(MYVAR)
行可以正确打印1.但是,当测试程序编译时,它设置a = 0。如何获得Fortran代码来识别MYVAR?
The echo $(MYVAR)
line correctly prints 1. However, when the test program is compiled it sets a=0. How do I get the Fortran code to recognize MYVAR?
推荐答案
您需要添加一个额外的标志
You need to add an extra flag
OPTIONS = -DMYVAR=$(MYVAR)
,然后用
and then you compile it with
all:
ifort $(OPTIONS) <file.f90> -fpp
你应该很好去。
这篇关于如何在makefile中定义一个变量,然后在Fortran代码中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文