看似不一致的Makefile行为(带Fortran)

时间:2015-02-01 19:56:29

标签: module makefile fortran

我在过去的一年里刚开始与Fortran合作工作,这是我第一次使用编译语言的重要经验。在工作中,我们使用管理编译和链接的开发环境。然而,为了让我的Fortran游戏得以实现,我已经开始在家中实现数据结构和算法。因此,我第一次踏入Makefile。

此时我只有两个程序,Linked ListQuick Find算法的实现。

(荒谬的基本)Makefile I wrote for the Linked List program链接和编译毫不费力。我尝试在链接列表示例之后对Quick Find Makefile进行建模,但由于某种原因,它无法生成.mod文件。此外,如果我通过以下方式显式生成.mod文件...

gfortran -c QuickFindUF.f90

... Makefile将编译并链接其余的没有抱怨。我确信我犯了一个菜鸟错误,但如果有人能够确定我的疏忽,我们将不胜感激。

更新:在回复评论时,我正在添加makefile的内容:

链接列表

# Makefile for the LinkedList test collection

# Define function to compile and link component scripts
ll_test: LinkedListTest.o LinkedList.o
    gfortran -o ll_test LinkedListTest.o LinkedList.o

# Define functions for each script that compile without linking
LinkedList.mod: LinkedList.o LinkedList.f90
    gfortran -c LinkedList.f90

LinkedList.o: LinkedList.f90
    gfortran -c LinkedList.f90

LinkedListTest.o: LinkedListTest.f90
    gfortran -c LinkedListTest.f90

# Define housekeeping function
clean:
    rm LinkedListTest.o LinkedList.o ll_test 

快速查找

# Makefile for the union_find collection

# Define function to compile and link component scripts
u_find: union_find.o QuickFindUF.o
    gfortran -o u_find union_find.o QuickFindUF.o

# Define functions for each script that compile without linking
QuickFindUF.mod: QuickFindUF.o QuickFindUF.f90
    gfortran -c QuickFindUF.f90

QuickFindUF.o: QuickFindUF.f90
    gfortran -c QuickFindUF.f90

union_find.o: union_find.f90
    gfortran -c union_find.f90

# Define housekeeping function
clean:
    rm union_find.o QuickFindUF.o u_find 

1 个答案:

答案 0 :(得分:1)

它是以下文件的顺序:

# Define function to compile and link component scripts
u_find: union_find.o QuickFindUF.o
    gfortran -o QuickFindUF.o u_find union_find.o

union_find.f90取决于QuickFindUF.f90生成的模块,但它首先编译union_find,因此它所需的模块尚不存在。

如果您切换订单以便首先构建QuickFindUF它将起作用:

# Define function to compile and link component scripts
    u_find: QuickFindUF.o union_find.o
        gfortran -o QuickFindUF.o u_find union_find.o

但更好的做法是利用他们列出的但不做任何事情的mod依赖:

QuickFindUF.mod: QuickFindUF.o QuickFindUF.f90
    gfortran -c QuickFindUF.f90

QuickFindUF.o: QuickFindUF.f90
    gfortran -c QuickFindUF.f90

union_find.o: union_find.f90 QuickFindUF.mod #Add the module dependency to union_find
    gfortran -c union_find.f90
相关问题