ubuntu11.04 下用gcc编译文件,编译几次后,其中一个.c文件被删除了,怎么回事?

我编了一个有头循环单链表,然后分成三个文件,分别是头文件(slist.h),测试文件(test.c),函数文件(slist.c)。一个文件用gcc编译没问题,但是分开后就出现

root@ubuntu:/home/uplooking/slist_head_loop# gcc -o slist.c test.c
/tmp/ccUOAE3w.o: In function `main':
test.c:(.text+0x2f): undefined reference to `init_head'
test.c:(.text+0x4d): undefined reference to `list_add'
test.c:(.text+0x61): undefined reference to `list_add_tail'
test.c:(.text+0x81): undefined reference to `list_del'
test.c:(.text+0x95): undefined reference to `list_for_each'
collect2: ld returned 1 exit status
请问是什么问题,.c文件都包含了所需要的头文件。而且编译几次后,slist.c文件就莫名其妙的没了,很纠结!

gcc 的 -o 参数后面跟的是编译链接完成后输出的可执行文件名,使用gcc -o slist.c test.c 后slist.c就变成了你要输出的可执行文件名,所以一执行就把slist.c删除了准备生成可执行文件,又由于slist.c被删除了所以编译不成功。
使用 gcc -o test slist.c test.c 最后生成的可执行文件为test
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-16
编译时加上 -lm
不行再试这个:
gcc -Wall fft.c /usr/lib/libm.a -o fft.out
追问

还是不行额,好多warning, 说是指针类型不兼容...

本回答被提问者采纳
相似回答