今天这样编译了一个程序,然后源程序就消失掉了...

arden1019 2006-03-13 04:31:17
例如:我的目录中有test.c 和一个编译好的test (使用 gcc -o test test.c)
然后我修改了一下 test.c 想重新编译一下,结果写成了:gcc -o test.c test
于是,报了一堆错误后我的test.c消失了。

我用
2>log
把错误都记下来啦,大家看看有什么可以告诉我的:

test(.rodata+0x0):/usr/src/build/90613-i386/BUILD/glibc-2.2.4/csu/init.c: multiple definition of `_fp_hw'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.rodata+0x0): first defined here
test: In function `_init':
test(.init+0x0): multiple definition of `_init'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o(.init+0x0): first defined here
test: In function `_start':
test(.text+0x0): multiple definition of `_start'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x0): first defined here
test(.fini+0x0):/usr/src/build/90613-i386/BUILD/glibc-2.2.4/csu/init.c: multiple definition of `_fini'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o(.fini+0x0): first defined here
test(.got+0x0):/usr/src/build/90613-i386/BUILD/glibc-2.2.4/csu/init.c: multiple definition of `_GLOBAL_OFFSET_TABLE_'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o(.got.plt+0x0): first defined here
test(.rodata+0x4):/usr/src/build/90613-i386/BUILD/glibc-2.2.4/csu/init.c: multiple definition of `_IO_stdin_used'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.rodata+0x4): first defined here
test(.data+0x0):/usr/src/build/90613-i386/BUILD/glibc-2.2.4/csu/init.c: multiple definition of `__data_start'
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.data+0x0): first defined here
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o(.dynamic+0x0): multiple definition of `_DYNAMIC'
test(.dynamic+0x0):/usr/src/build/90613-i386/BUILD/glibc-2.2.4/csu/init.c: first defined here
collect2: ld returned 1 exit status
...全文
208 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
arden1019 2006-03-15
  • 打赏
  • 举报
回复
:)
YanDong_8212 2006-03-14
  • 打赏
  • 举报
回复
-o 后面跟目标文件,覆盖了test.c







yzx1983 2006-03-14
  • 打赏
  • 举报
回复
编译的时候要把你给出的源文件和库文件进行连接,生成的elf格式文件(可执行)里面就有各个函数的函数可执行码。

你把一个已经是elf格式的文件再与库文件连接,于是库函数就出现了两次,这就是重复定义的原因。

test.c文件被用作输出文件,但是编译出错了,于是它就被删除了。如果编译成功,它就被生成的新elf文件所取代。
AlphaCN_NET 2006-03-14
  • 打赏
  • 举报
回复
目标文件是要清掉的
arden1019 2006-03-14
  • 打赏
  • 举报
回复
我知道是弄反了,
我想知道些其它的内容
比如说,gcc在把这个二进制test当作源码编译的时候,出现的这些multiple definition 错误是什么意思。为什么我的test.c文件不见了?
UltraEdit32 2006-03-13
  • 打赏
  • 举报
回复
弄反了。

是gcc -o test test.c

写成gcc -o test.c test的话,gcc就会试图把test编译成test.c,于是就出现以上的错误。

23,118

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧