无法编译c代码
问题描述:
我是C新手,无法编译我下载的程序。 的ERRORMESSAGE看起来是这样的:无法编译c代码
********@*******:~/Desktop/GRAPPA20$ gcc all_sorting_reversals.c
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o: In function `_start':
/build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
/tmp/ccwl1p7v.o: In function `find_all_sorting_reversals':
all_sorting_reversals.c:(.text+0x536): undefined reference to `clear_list'
all_sorting_reversals.c:(.text+0x55c): undefined reference to `clear_list'
all_sorting_reversals.c:(.text+0x5c5): undefined reference to `push'
all_sorting_reversals.c:(.text+0x5fe): undefined reference to `clear_list'
all_sorting_reversals.c:(.text+0x61f): undefined reference to `clear_list'
all_sorting_reversals.c:(.text+0x71d): undefined reference to `push'
all_sorting_reversals.c:(.text+0x767): undefined reference to `list_size'
all_sorting_reversals.c:(.text+0x791): undefined reference to `list_size'
all_sorting_reversals.c:(.text+0x7fe): undefined reference to `list_size'
all_sorting_reversals.c:(.text+0x830): undefined reference to `list_get'
的代码可以看出:http://pastebin.com/d749ec13a
答
这是一个链接错误后,你的答案。这是因为链接器找不到某些函数的实现而发生的。在这种情况下,函数看起来并不像库中的函数。所以最可能的原因是你没有编译所有需要的C源文件。
您是否检查过程序是否有make文件?
编辑:很容易从您的发布代码中看到这一点。缺少的函数(clear_list,push等)只是没有在该文件中定义。
答
看起来你需要转发声明的一切。
在C中,编译器从上到下读取所有内容,因此如果您调用一个方法,并且该方法在代码中进一步定义,则需要转发声明它。
例如,这不会工作:
int main()
{
doStuff();
return 0;
}
void doStuff()
{
int foo = 3;
}
..但这个意志:
void doStuff()
{
int foo = 3;
}
int main()
{
doStuff();
return 0;
}
另一种可能是您要编译C++代码与C编译器。列表被简单地创建为类,所以如果你的代码中有任何class decleration,它就是C++ :)
再一次,你需要发布代码(或链接到它),因为这些消息,我们不能给你一个明确的答案。
[编辑] NVM,这显然是没有看到的源代码:)
答
看起来像all_sorting_reversals.c
不包含main()方法,它期望与提供其他缺少方法(list_get,list_size等)的其他对象/库链接。
答
好像你不编译所需的所有文件,仅编译单个文件,这反过来不具备的主要功能
答
看起来你可能会丢失一些库。
答
似乎无法定位诸如“clear_list”,“push”等功能的定义。查找包含这些定义的库/对象/文件,然后验证它们是否与您的应用程序正确链接。
你可以发布你的C代码吗? – NinethSense 2009-06-08 10:23:59
当然,我编辑了我的第一篇文章:) – n00ki3 2009-06-08 10:28:15