【问题标题】:multiple definition of '_start''_start' 的多重定义
【发布时间】:2016-09-24 23:19:02
【问题描述】:

我的 makefile 代码出现错误,我不知道如何修复它,我在网站上搜索了答案并最终创建了一个帐户来寻求帮助 这是错误代码

date.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
date.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o (.fini+0x0): first defined here
date.o:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o (.rodata.cst4+0x0): first defined here
date.o: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
date.o: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/5/crtbegin.o:(.data+0x0): first defined here
date.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o (.init+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/5/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
date.o:(.data+0x10): first defined here
/usr/bin/ld: error in date.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'testdate' failed
make: *** [testdate] Error 1

还有我的makefile

testdate: date.o testdate.o
        g++ -Wall -o testdate.o date.o

date.o: date.h date.cpp
        g++ -Wall -c date.cpp
testdate.o: date.h testdate.cpp
        g++ -Wall -c testdate.cpp

【问题讨论】:

  • 对我来说,这似乎与 makefile 无关,但与您的 C++ 代码有关。
  • 您的第一条规则中的命令看起来不对。 -o 后面的单词应该是您希望 g++ 构建的文件的名称。

标签: c++ ubuntu makefile


【解决方案1】:

规则

testdate: date.o testdate.o
        g++ -Wall -o testdate.o date.o

应该是

testdate: date.o testdate.o
        g++ -Wall -o testdate testdate.o date.o
#                    ^^^^^^^^

或避免重复自己:

testdate: date.o testdate.o
        g++ -Wall $^ -o $@

(这应该产生g++ -Wall date.o testdate.o -o testdate

确实,您可能需要考虑:

testdate: date.o testdate.o
        g++ -Wall $^ -o $@
date.o: date.cpp date.h
    g++ -Wall -c $< -o $@
testdate.o: testdate.cpp date.h
    g++ -Wall -c $< -o $@

$^ 是所有依赖项,$&lt; 只是第一个,$@ 是当前目标。

有关 Makefile 规则的更多信息:https://www.chemie.fu-berlin.de/chemnet/use/info/make/make_4.html

【讨论】:

  • 你定义了$^和$
  • 啊,$@是当前目标,所以testdate: ...$@testdate
  • 我用您在第三个示例中发布的确切代码进行了尝试,它仍然给出了相同的错误,有没有办法阻止makefile定义_start
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 2017-11-29
相关资源
最近更新 更多