Build Scons-Fortran文件的生成顺序

Build Scons-Fortran文件的生成顺序,build,module,fortran,scons,Build,Module,Fortran,Scons,在Fortran中构建模块需要按特定顺序进行,例如,如果文件a.f需要在B.f中定义的模块,则B.f需要先编译。我如何在SCON中强制执行这种构建顺序?如果我向它提供源文件列表,它会按字母顺序排列它们(因此a.f在B.f之前编译)。我读过关于Requires()和dependens()函数的文章,但没能让它们为我工作 我很乐意按照需要编译的顺序列出源文件(因此禁用按字母顺序重新排列),但也欢迎任何其他方法 根据Kyle的要求,这是我的Sconscript和构建日志: # Main program

在Fortran中构建模块需要按特定顺序进行,例如,如果文件
a.f
需要在
B.f
中定义的模块,则
B.f
需要先编译。我如何在SCON中强制执行这种构建顺序?如果我向它提供源文件列表,它会按字母顺序排列它们(因此
a.f
B.f
之前编译)。我读过关于
Requires()
dependens()
函数的文章,但没能让它们为我工作

我很乐意按照需要编译的顺序列出源文件(因此禁用按字母顺序重新排列),但也欢迎任何其他方法

根据Kyle的要求,这是我的Sconscript和构建日志:

# Main program building script

Import('env')

PROGRAM = 'main.exe'

SRC_PREFIX = './src/'

SRC = [ 'array_1D_module.f', 
            'array_2D_module.f', 
            'array_3D_module.f', 
            'thomas_algorithm_module.f',
            'histogram_module.f',
            'histogram_computer_module.f',
            'density_parameters_module.f',
            'diffusion3D_aos_z_sub_solver_module.f',
            'diffusion3D_aos_y_sub_solver_module.f',
            'diffusion3D_aos_x_sub_solver_module.f',
            'diffusion3D_aos_solver_module.f',
            'nonlinear_diffusion_utilities_module.f',
            'nonlinear_diffusion_parameters_module.f',
            'derivative_magnitude_computer_module.f',
            'nonlinear_diffusion_module.f',
            'main_module.f',
            'main.f' ]

# Attach prefix to each source file
for i in range( len(SRC) ) :
    SRC[i] = SRC_PREFIX + SRC[i]


env.Program(target = PROGRAM, source = SRC)
这产生了:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
ifort -o src/array_1D_module.o -c src/array_1D_module.f
ifort -o src/array_2D_module.o -c src/array_2D_module.f
ifort -o src/array_3D_module.o -c src/array_3D_module.f
ifort -o src/density_parameters_module.o -c src/density_parameters_module.f
ifort -o src/derivative_magnitude_computer_module.o -c src/derivative_magnitude_computer_module.f
ifort -o src/diffusion3D_aos_solver_module.o -c src/diffusion3D_aos_solver_module.f
src/diffusion3D_aos_solver_module.f(7): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [DIFFUSION3D_AOS_Z_SUB_SOLVER_MODULE]
    use diffusion3D_aos_z_sub_solver_module, only :
------------^
因此,
density\u parameters\u module.f
是在
thomas\u algorithm\u module.f
之前编译的,即使在我的列表中它在后面。

您的程序(如建议的)是否使用模块?这里有几个陷阱:

  • FORTRANMODDIR需要定义:请参阅以了解有关该定义的讨论
  • 我发现包含模块定义和源代码的混合源文件会造成一定程度的混乱

  • 您需要按照适当的顺序定义列表,其余的由SCON来完成。IDK是肯定的,因为我不使用Scons。@KyleKanos-正如我所说,Scons会按照字母顺序重新排列您的列表。我的构建日志证实了这一点,您提供的示例也证实了这一点。我刚刚下载并测试了它。我创建了
    bee.f90
    ae.f90
    print_lot.f90
    ,最后一个取决于
    ae
    ae
    取决于
    bee
    。该列表是
    Program('Program',['bee.f90','ae.f90','print\u a_lot.f90'])
    。在终端中键入
    scons
    对我来说很好,没有颠倒顺序。我还将我的列表更改为
    程序(['print\u lot.f90'、'bee.f90'、'ae.f90'])
    ,并且也能够正确地编译它。也许你可以发布你的
    SConstruct
    文件?@Kyle-按要求编辑当我为我的
    .f90
    文件集复制OP的SConstruct文件时,我也收到了一个失败。但是,按照链接讨论中的建议添加
    FORTRANMODDIR
    ,允许
    scons
    以正确的顺序编译。希望同样的方法也适用于OP.Wiii,FORTRANMODDIR成功了!谢谢你,汤姆。是的,我使用的是模块,并没有在同一个文件中混合使用非模块代码。