使用Makefile编译F90时出错

时间:2018-03-15 18:56:00

标签: makefile fortran gnu-make gfortran

我的源f90代码包括:

(1)module:dat_io.f90,dimconvert.f90

(2)main:elastic_2D.f90

以下是我的Makefile:

FC=gfortran
FCFLAGS=-Wall -O3
FLFLAGS=-mcmodel=large
SRCS = $(wildcard *.f90)
EXES = $(patsubst %.f90,%,$(SRCS))
%.o: %.f90
    $(FC) $(FCFLAGS) -c $<
SRC_CODE=\
        dat_io.f90\
        dimconvert.f90\
        elastic_2D.f90
OBJ = $(SRC_CODE:%.f90=%.o)
elastic: $(OBJ)
    $(FC) $^ $(FLFLAGS) -o $@
clean:
    rm -rf *.o *.mod *~ $(EXES)
all: clean elastic

虽然我使用-mcmodel=large来避免&#34;重定位被截断以适应&#34;错误,当我make时,仍会弹出一些错误:

elastic_2D.o: In function `MAIN__':
elastic_2D.f90:(.text+0x167): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x1ce): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x23a): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x2b9): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x320): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x38c): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x40b): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x472): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x4de): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x530): relocation truncated to fit: R_X86_64_32S against `.bss'
elastic_2D.f90:(.text+0x5e8): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
make: *** [elastic] Error 1

这里有什么问题,如何修改?

1 个答案:

答案 0 :(得分:2)

使用-mcmodel=选项时,在编译和链接时使用此选项很重要。在这里的Makefile中,-mcmodel=large仅在链接阶段给出(通过FLFLAGS)。

将此选项添加到FCFLAGS此处也将在编译时使用它。