使用fortran自动制作:文件顺序 [英] automake with fortran: order of file

查看:147
本文介绍了使用fortran自动制作:文件顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用自动工具构建代码时,我遇到了一个小问题. 我的文件结构是:

I am facing a small problem when trying to build my code with autotools. My file structure is:

$ tree 
.
|-- configure.ac
|-- Makefile.am
`-- src
    |-- constants.f90
    |-- environment.f90
    |-- init.f90
    |-- main.f90
    `-- util.f90

(删除了可能不必要的行) 而我的Makefile.am是:

(deleted possibly unnecessary lines) and my Makefile.am is:

#SUBDIRS= help
bin_PROGRAMS = scasr
scasr_SOURCES = \ 
                src/constants.f90  src/environment.f90  src/util.f90 \
                src/init.f90 src/main.f90 
scasr_LDADD = 
EXTRA_DIST= autogen.sh
CLEANFILES =*.mod 

问题是src/(*.f90)的,除了main.f90是模块.因此,如果我 必须手动编写makefile,我将拥有:

The problem is src/(*.f90)'s except main.f90 are module. Hence, if I have to write the makefile by hand, I will have:

constants.o : constants.f90 
environment.o : environment.f90 
init.o : init.f90 util.o constants.o 
main.o : main.f90 init.o constants.o environment.o 
util.o : util.f90 constants.o 

因此,对于Makefile.am,我必须对文件进行严格排序 scasr_SOURCES. IE. 来源为:

so, for Makefile.am, I have to make a strict order of files in scasr_SOURCES. i.e. with the sources as :

scasr_SOURCES = \ 
                src/constants.f90  src/environment.f90  src/util.f90 \
                src/init.f90 src/main.f90 

它可以编译. 但是如果我有:

It compiles fine. But if I have as:

scasr_SOURCES = src/main.f90 \ 
                src/constants.f90  src/environment.f90  src/util.f90 \
                src/init.f90  

我收到错误消息:

make  all-am
make[1]: Entering directory `/home/rudra/Programs/ScASR/trunk'
gfortran  -g -O2 -c -o src/main.o src/main.f90
src/main.f90:7.4:

use mget_env
    1
Fatal Error: Can't open module file 'mget_env.mod' for reading at (1):
No such file or directory
make[1]: *** [src/main.o] Error 1

是否有任何出路,以便make/configure通过以下方式检查依赖关系: 本身?还是我必须保持严格的秩序?

Is there any way out so that make/configure will check the dependency by itself? Or I must keep a strict order?

推荐答案

(评论中的答案.请参见

(Answers in the comments. See Question with no answers, but issue solved in the comments (or extended in chat) )

@Stefan写道:

@Stefan wrote:

您可以直接将依赖项输入到Makefile.am.因此,只需将手写的Makefile规则(帖子中的第三个代码部分)放在Makefile.am中.据我所知,自动依赖项跟踪是不可能的.这可能会因添加子模块而改变,这些子模块在Fortran 2008中定义,但尚未在任何流行的编译器中实现.

You could enter the dependencies directly to your Makefile.am. So simply put your handwritten Makefile rules (the third code part in your post) in the Makefile.am. Automatic dependency tracking is, as far as I know, not (yet) possible. This could change with the addition of submodules, which are defined in Fortran 2008 but not yet implemented in any popular compiler.

OP写道:

按照@Stefan的评论,我已经在make文件中添加了依赖项,从而解决了该问题.我已经测试过,源代码的顺序不再重要.由于互联网上没有太多可用的东西,因此我将完整的步骤放在这里:

As per @Stefan's comment, I have added the dependencies in make file, and that solved the problem. I have tested that the order of source code is not important anymore. Since, there is not many stuff in internet available, I am putting the complete procedure here:

  1. 创建一个依赖项列表(makedepf90是一个不错的选择)
  1. create a dependency list (makedepf90 is a good option)

$ makedepf90 src/*.f90 src/constants.o : src/constants.f90 src/environment.o : src/environment.f90 src/init.o : src/init.f90 src/util.o src/constants.o src/main.o : src/main.f90 src/init.o src/constants.o src/environment.o src/util.o : src/util.f90 src/constants.o

  1. 只需将步骤1的输出复制并粘贴到scasr_SOURCES之后:

scasr_SOURCES = src/main.f90\ src/constants.f90 src/environment.f90 rc/util.f90 src/init.f90 src/constants.o : src/constants.f90 src/environment.o : src/environment.f90 src/init.o : src/init.f90 src/util.o src/constants.o src/main.o : src/main.f90 src/init.o src/constants.o src/environment.o src/util.o : src/util.f90 src/constants.o

注意:如果您将其放在makefile中的其他位置,我尚未测试它是否可以工作.但这是可行的.

NB: I have not tested if it will work if you place it some place else in the makefile. But this is working.

这篇关于使用fortran自动制作:文件顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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