gcc 编译过程问题

gcc 编译过程问题

写个hello.c 程序,


生成


hello.c -> 预处理 gcc -E hello.c -o hello.i     执行没问题;

预处理 -> 汇编 gcc -S hello.i -o hello.s   执行也没问题;

汇编 -> 目标文件 gcc -c hello.s -o hello.o  执行也没问题;

目标文件 -> 可执行文件  gcc hello.o -o hello 执行报了这个错误,如下:


hello.o: In function `_fini':

(.fini+0x0): multiple definition of `_fini'

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o:(.fini+0x0): first defined here

hello.o: In function `data_start':

(.data+0x0): multiple definition of `__data_start'

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.data+0x0): first defined here

hello.o:(.rodata+0x8): multiple definition of `__dso_handle'

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o:(.rodata+0x0): first defined here

hello.o:(.rodata+0x0): multiple definition of `_IO_stdin_used'

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.rodata.cst4+0x0): first defined here

hello.o: In function `_start':

(.text+0x0): multiple definition of `_start'

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o:(.text+0x0): first defined here

hello.o: In function `_init':

(.init+0x0): multiple definition of `_init'

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o:(.init+0x0): first defined here

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'

hello.o:(.data+0x8): first defined here

/bin/ld: error in hello.o(.eh_frame); no .eh_frame_hdr table will be created.

collect2: error: ld returned 1 exit status


???


但运行 hello.o 已经可以执行了。


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
大白老师 8天前
你这个应该是gcc 四个步骤中某个写错了,hello.o应该是不能直接运行的
中年猿叔 2025-10-03 19:18:59
把代码截图看一下
  • 提问者 柳絮飞花 #1

    https://img1.sycdn.imooc.com/climg/99f1f86809dfce7914440548.jpg

    2025-10-03 21:24:13
  • 中年猿叔 回复 提问者 柳絮飞花 #2

    您用的是redhat吗?用我们提供的Ubuntu测试一下呢,代码没问题,按流程做不应该有问题

    2025-10-04 10:08:42
  • 提问者 柳絮飞花 回复 中年猿叔 #3

    我用的是移动云服务器,CentOS 系统。

    2025-10-08 13:40:37
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
物联网/嵌入式全能工程师(提薪优选)
  • 参与学习       521    人
  • 提交作业       288    份

行业热门,政策风口,人才缺口极大,现在入场时机正好! 上千人检验,数轮迭代的硬核知识体系,0基础友好入行/转行 保姆式教学+简历指导+1V1模拟面试+3次内推,助力轻松就业!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师