运行makefile时出错

运行makefile时出错,makefile,fortran,Makefile,Fortran,运行makefile时,出现以下错误: 我已经读到,这可能是由于在makefile中两次输入相同的名称造成的,但我想我没有。如果没有标志,它编译和链接不会出现问题 hmatrices: In function `_start': (.text+0x0): multiple definition of `_start' /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:/build /buildd/g

运行makefile时,出现以下错误: 我已经读到,这可能是由于在makefile中两次输入相同的名称造成的,但我想我没有。如果没有标志,它编译和链接不会出现问题

 hmatrices: In function `_start':
 (.text+0x0): multiple definition of `_start'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:/build     /buildd/glibc-2.21/csu/../sysdeps/x86_64/start.S:63: first defined      here
hmatrices: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o:/build    /buildd/glibc-2.21/csu/../sysdeps/x86_64/crti.S:80: first defined here
 hmatrices:(.rodata+0x0): multiple definition of `_IO_stdin_used'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:    (.rodata.cst4+0x0): first defined here
   hmatrices: In function `data_start':
 (.data+0x0): multiple definition of `__data_start'
   /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o:          (.data+0x0): first defined here
      hmatrices: In function `data_start':
  (.data+0x8): multiple definition of `__dso_handle'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o:(.data+0x0): first defined here
 hmatrices: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o:/build/buildd/glibc-2.21/csu/../sysdeps/x86_64/crti.S:64: first defined here
DataModule.o:(.data+0x0): multiple definition of `__datamodule_MOD_maxerror'
hmatrices:(.data+0x10): first defined here
 InputOutputModule.o: In function `__inputoutputmodule_MOD_writematrix':
InputOutputModule.f90:(.text+0x0): multiple definition of     `__inputoutputmodule_MOD_writematrix'
 hmatrices:(.text+0xf6): first defined here
 InputOutputModule.o: In function `__inputoutputmodule_MOD_readmatrix':
 InputOutputModule.f90:(.text+0x1c57): multiple definition of `__inputoutputmodule_MOD_readmatrix'
 hmatrices:(.text+0x1d4d): first defined here
 TestIOModule.o: In function `__testiomodule_MOD_testio':
 TestIOModule.f90:(.text+0x0): multiple definition of `__testiomodule_MOD_testio'
 hmatrices:(.text+0x2f63): first defined here
 HelpModule.o: In function `__helpmodule_MOD_printhelpargument':
 HelpModule.f90:(.text+0x0): multiple definition of     `__helpmodule_MOD_printhelpargument'
 hmatrices:(.text+0x3158): first defined here
 HelpModule.o: In function `__helpmodule_MOD_printhelp':
 HelpModule.f90:(.text+0x98): multiple definition of    `__helpmodule_MOD_printhelp'
 hmatrices:(.text+0x31f0): first defined here
 MathModule.o: In function `__mathmodule_MOD_solve':
MathModule.f90:(.text+0x0): multiple definition of `__mathmodule_MOD_solve'
hmatrices:(.text+0x326a): first defined here
MathModule.o: In function `__mathmodule_MOD_svd':
MathModule.f90:(.text+0x475): multiple definition of `__mathmodule_MOD_svd'
hmatrices:(.text+0x36df): first defined here
MathModule.o: In function `__mathmodule_MOD_matrixproduct':
MathModule.f90:(.text+0x15a2): multiple definition of `__mathmodule_MOD_matrixproduct'
 hmatrices:(.text+0x480c): first defined here
 MathModule.o: In function `__mathmodule_MOD_matprod':
 MathModule.f90:(.text+0x1d26): multiple definition of `__mathmodule_MOD_matprod'
hmatrices:(.text+0x4f90): first defined here
MathModule.o: In function `__mathmodule_MOD_full':
MathModule.f90:(.text+0x2e3e): multiple definition of `__mathmodule_MOD_full'
hmatrices:(.text+0x60a8): first defined here
TestMathModule.o: In function `__testmathmodule_MOD_testmath':
TestMathModule.f90:(.text+0xa4c): multiple definition of `__testmathmodule_MOD_testmath'
hmatrices:(.text+0x6ddd): first defined here
EquationModule.o: In function `__equationmodule_MOD_plotfield':
EquationModule.f90:(.text+0x8f8): multiple definition of `__equationmodule_MOD_plotfield'
hmatrices:(.text+0x76ea): first defined here
EquationModule.o: In function `__equationmodule_MOD_solveintfull':
 EquationModule.f90:(.text+0x1695): multiple definition of `__equationmodule_MOD_solveintfull'
hmatrices:(.text+0x8487): first defined here
EquationModule.o: In function `__equationmodule_MOD_makegfull':
EquationModule.f90:(.text+0x1eb7): multiple definition of `__equationmodule_MOD_makegfull'
hmatrices:(.text+0x8ca9): first defined here
LowRankModule.o: In function `__lowrankmodule_MOD_lowrank':
LowRankModule.f90:(.text+0x10c9): multiple definition of `__lowrankmodule_MOD_lowrank'
hmatrices:(.text+0xa118): first defined here
TestLRModule.o: In function `__testlrmodule_MOD_testlr':
TestLRModule.f90:(.text+0x0): multiple definition of `__testlrmodule_MOD_testlr'
 hmatrices:(.text+0xa32e): first defined here
TestModule.o: In function `__testmodule_MOD_constructiontests':
TestModule.f90:(.text+0x47b2): multiple definition of `__testmodule_MOD_constructiontests'
 hmatrices:(.text+0xeaff): first defined here
TestModule.o: In function `__testmodule_MOD_test':
TestModule.f90:(.text+0x47c2): multiple definition of `__testmodule_MOD_test'
hmatrices:(.text+0xeb0f): first defined here
Main.o: In function `main':
Main.f90:(.text+0xbb5): multiple definition of `main'
hmatrices:(.text+0xf7b2): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o:(.tm_clone_table+0x0):    multiple definition of `__TMC_END__'
hmatrices:(.data+0x18): first defined here
/usr/bin/ld: error in hmatrices(.eh_frame); no .eh_frame_hdr table will be created.
 collect2: error: ld returned 1 exit status
 Makefile:14: recipe for target 'hmatrices' failed
make: *** [hmatrices] Error 1
这是我的制作文件

 # Makefile for "TWS: Project H-matrices: part 1"

 ####

 # Variable for the selected compiler.
 FC = gfortran

 # Compiler flags:
 # -Not needed yet-
 FFLAGS=

 # Linking step:
 hmatrices: DataModule.o InputOutputModule.o TestIOModule.o HelpModule.o MathModule.o TestMathModule.o EquationModule.o LowRankModule.o TestLRModule.o TestModule.o  Main.o 
$(FC) -o -fbounds-check hmatrices DataModule.o InputOutputModule.o TestIOModule.o HelpModule.o   MathModule.o TestMathModule.o EquationModule.o LowRankModule.o TestLRModule.o TestModule.o Main.o -L/usr/local/lib -llapack -lblas
 # Compilation step:
 # -f.90 files bevinden zich in src-
 DataModule.o: ./src/DataModule.f90
$(FC) -c ./src/DataModule.f90

 TestIOModule.o: ./src/TestIOModule.f90
$(FC) -c ./src/TestIOModule.f90

 HelpModule.o: ./src/HelpModule.f90
$(FC) -c ./src/HelpModule.f90

TestModule.o: ./src/TestModule.f90
$(FC) -c ./src/TestModule.f90

 InputOutputModule.o: ./src/InputOutputModule.f90
$(FC) -c ./src/InputOutputModule.f90

 MathModule.o: ./src/MathModule.f90
$(FC) -c ./src/MathModule.f90

 TestMathModule.o: ./src/TestMathModule.f90
$(FC) -c ./src/TestMathModule.f90

EquationModule.o: ./src/EquationModule.f90
$(FC) -c ./src/EquationModule.f90

 LowRankModule.o: ./src/LowRankModule.f90
$(FC) -c ./src/LowRankModule.f90

TestLRModule.o: ./src/TestLRModule.f90
$(FC) -c ./src/TestLRModule.f90

  Main.o: ./src/Main.f90
$(FC) -c ./src/Main.f90

   # Deze lijn maakt het mogelijk om "make clean" te gebruiken.
   clean:
    rm -f -r *.o *.mod 

# Om de compilatie te forceren wanneer hmatrices reeds bestaat.
 .PHONY: hmatrices

我相信你的编译命令是错误的

我怀疑您曾经手动编译过
hmatrices
(或者使用早期的makefile),并且当前将其保存在您的目录中

编译命令是
$(FC)-o-fbounds check hmatrices…
,但它将
-o
选项与其
hmatrices
参数分开。因此,您告诉
$(FC)
创建
-fbounds检查
二进制文件,并链接所有
.o
文件和先前存在的
hmatrices
二进制文件。这就是重复符号的来源

修正你的论点顺序,你就会修正你的问题

也就是说,这个makefile并没有利用它提供的许多特性。它可以简化为以下内容

# Makefile for "TWS: Project H-matrices: part 1"

####

# Variable for the selected compiler.
FC = gfortran

# Compiler flags:
# -Not needed yet-
FFLAGS=

# Linking step:
hmatrices: DataModule.o InputOutputModule.o TestIOModule.o HelpModule.o MathModule.o TestMathModule.o EquationModule.o LowRankModule.o TestLRModule.o TestModule.o  Main.o 
        $(FC) -fbounds-check -o $@ $^ -L/usr/local/lib -llapack -lblas

# Compilation step:
# -f.90 files bevinden zich in src-
%.o: ./src/%.f90
        $(FC) -c $<

# Deze lijn maakt het mogelijk om "make clean" te gebruiken.
clean:
    rm -f -r *.o *.mod
“TWS:项目H-矩阵:第1部分”的Makefile #### #所选编译器的变量。 FC=gfortran #编译器标志: #-还不需要- FFLAGS= #链接步骤: hmatrices:DataModule.o InputOutputModule.o Testimodule.o HelpModule.o MathModule.o TestMathModule.o EquationModule.o LowRankModule.o TestlModule.o TestModule.o Main.o $(FC)-fbounds check-o$@$^-L/usr/local/lib-llapack-lblas #编译步骤: #src中的-f.90文件bevinden zich- %.o:./src/%.f90 $(FC)-c$< #这是一种“清洁”的方式。 清洁: rm-f-r*.o*.mod
注意,我还删除了
.PHONY:hmatrices
行,因为这是不正确的。您不希望
hmatrices
成为虚假目标。你想把它当作正常的目标。(因此make仅在必要时重建它,而不是每次命中目标时都重建。)

现在获取缺少的分隔符。停止第14行错误配方行需要前导制表符,而不是空格。你需要在当地做这件事。