运行我的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
这是我的make文件
# 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
答案 0 :(得分:1)
我相信您的编译命令不正确。
我怀疑您是在某一点(或使用较早的makefile)手动编译hmatrices
并且目前在您的目录中有它?
您的编译命令为$(FC) -o -fbounds-check hmatrices ...
,但会将-o
选项与其hmatrices
参数分开。因此,您要告诉$(FC)
创建-fbounds-check
二进制文件,并在所有.o
个文件和中链接预先存在的hmatrices
二进制文件。这是重复符号的来源。
修正您的参数订单,然后解决问题。
那说makefile并没有充分利用make提供的许多功能。它可以简化为以下内容。
# 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
请注意,我还删除了.PHONY: hmatrices
行,因为这是不正确的。你不希望hmatrices
成为虚假的目标。您希望将其视为正常目标。 (因此,只有在必要时才重建它,而不是每次击中目标时都重建它。)