如何使用静态库';基于Makefile';s配置

如何使用静态库';基于Makefile';s配置,makefile,module,compilation,fortran,gpu,Makefile,Module,Compilation,Fortran,Gpu,我正在以这种方式将以下模块(从静态库)导入名为initprogram.f90的文件中: use device_info 但是,我只希望在Makefile中选择此选项时包含此库: ifeq ($(strip $(WITH_GPU)),1) (使用GPU时,GPU等于1)。如果我没有使用GPU,device_info.mod应该不可用,因为我不需要它。我该怎么做 基本上我想消除这个错误: Fatal Error: Can't open module file 'device_info.mod'

我正在以这种方式将以下模块(从静态库)导入名为initprogram.f90的文件中:

use device_info
但是,我只希望在Makefile中选择此选项时包含此库:

ifeq ($(strip $(WITH_GPU)),1) 
(使用GPU时,GPU等于1)。如果我没有使用GPU,device_info.mod应该不可用,因为我不需要它。我该怎么做

基本上我想消除这个错误:

Fatal Error: Can't open module file 'device_info.mod' for reading at (1): No such file or directory
在没有定义device_info.mod的库的情况下编译时。

您可能需要:

  • 在Fortran源文件中隐藏或不隐藏
    使用设备信息
    声明的预处理器,具体取决于传递给它的选项。您的Fortran编译链中有预处理器吗?如果是,您知道如何从命令行传递选项,以及如何在源文件中使用它们来隐藏或不隐藏部分代码吗

  • 将正确的选项从Makefile传递给编译器链

  • 假设您有一个预处理器,它有一个
    #ifdef
    -
    #endif
    宏。我们还假设编译器链从命令行获取选项
    -D MACRO=VALUE
    。假设编译器命令的语法如下所示:

    <compiler-name> <options> <source-file> -o <binary-output-file>
    
    然后,编辑生成文件:

    COMPILER           := <whatever-compiler-you-use>
    COMPILER_FLAGS     := <whatever-compiler-options-you-need-by-default>
    OTHER_DEPENDENCIES := <whatever-default-dependencies>
    
    ifeq ($(strip $(WITH_GPU)),1) 
    COMPILER_FLAGS     += -D WITH_GPU=1
    OTHER_DEPENDENCIES += device_info.mod
    endif
    
    initprogram.exe: initprogram.f90 $(OTHER_DEPENDENCIES)
        $(COMPILER) $(COMPILER_FLAGS) $< -o $@
    
    编译器:=
    编译器\u标志:=
    其他依赖项:=
    ifeq($(带GPU的带$),1)
    编译器\u标志+=-D,且\u GPU=1
    其他依赖项+=设备信息.mod
    恩迪夫
    initprogram.exe:initprogram.f90$(其他依赖项)
    $(编译器)$(编译器标志)$<-o$@
    
    $the.mod(模块)实际上不是库的一部分。。。
    
    COMPILER           := <whatever-compiler-you-use>
    COMPILER_FLAGS     := <whatever-compiler-options-you-need-by-default>
    OTHER_DEPENDENCIES := <whatever-default-dependencies>
    
    ifeq ($(strip $(WITH_GPU)),1) 
    COMPILER_FLAGS     += -D WITH_GPU=1
    OTHER_DEPENDENCIES += device_info.mod
    endif
    
    initprogram.exe: initprogram.f90 $(OTHER_DEPENDENCIES)
        $(COMPILER) $(COMPILER_FLAGS) $< -o $@