简体   繁体   中英

can't compile c code

I'm new to C and i can't compile a program i downloaded. The Errormessage looks like this :

    ********@*******:~/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'

The Code can be seen in : http://pastebin.com/d749ec13a

好像all_sorting_reversals.c不包含main()方法,它希望与提供其他缺少方法(list_get,list_size等)的其他对象/库链接。

This is a linker error. It is occurring because the linker can not find the implementation of certain functions. In this case, the functions don't look like they're from a library. So the most likely cause is you are not compiling in all the C source files required.

Did you check to see whether the program has a make file?

EDIT: It's easy to see this from your posted code. The missing functions (clear_list, push, etc.) simply aren't defined in that file.

似乎您没有编译所有需要的文件,而仅编译了一个文件,而后者又没有主要功能

看起来您可能缺少某些库。

It seems to be that the definition of functions such as "clear_list", "push" etc, cannot be located. Look for the libraries/objects/files containing these definition and then verify if they are linked properly to you application.

Looks like you need to forward declare everything.

In C, the compiler reads everything from top-to-bottom, so if you call a method, and the method is defined further down in your code, you need to forward declare it.

For example, this wont work:

int main()
{
   doStuff();
   return 0;
}
void doStuff()
{
   int foo = 3;
}

.. but this will:

void doStuff()
{
   int foo = 3;
}
int main()
{
   doStuff();
   return 0;
}

Another possibility is that you are trying to compile C++ code with a C compiler. Lists are ussually created as classes, so if you got any class decleration in your code, it's C++ :)

Again, you need to post the code (or link to it), cause from those messages, we can't give you a definite answer.

[EDIT] Nvm, this clearly ain't your answer after seeing the source code :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM