Thomas D.
Thomas D.

Reputation: 87

Error compiling F90 using Makefile

My source f90 codes include:

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

(2) main: elastic_2D.f90

The following is my 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

Although I used -mcmodel=large to avoid "relocation truncated to fit" error, when I make it, some errors still pop up says:

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

What is wrong here and how do I revise it?

Upvotes: 2

Views: 566

Answers (1)

francescalus
francescalus

Reputation: 32366

When using an -mcmodel= option it is important to use this when compiling as well as when linking. In the Makefile here, -mcmodel=large is given (through FLFLAGS) only at the link stage.

Adding the option to FCFLAGS here will use it at compile time also.

Upvotes: 2

Related Questions