2009-06-08 296 views
0

我是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

+3

你可以發佈你的C代碼嗎? – NinethSense 2009-06-08 10:23:59

+0

當然,我編輯了我的第一篇文章:) – n00ki3 2009-06-08 10:28:15

回答

4

這是一個鏈接錯誤後,你的答案。這是因爲鏈接器找不到某些函數的實現而發生的。在這種情況下,函數看起來並不像庫中的函數。所以最可能的原因是你沒有編譯所有需要的C源文件。

您是否檢查過程序是否有make文件?

編輯:很容易從您的發佈代碼中看到這一點。缺少的函數(clear_list,push等)只是沒有在該文件中定義。

-3

看起來你需要轉發聲明的一切。

在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,這顯然是沒有看到的源代碼:)

6

看起來像all_sorting_reversals.c不包含main()方法,它期望與提供其他缺少方法(list_get,list_size等)的其他對象/庫鏈接。

2

好像你不編譯所需的所有文件,僅編譯單個文件,這反過來不具備的主要功能

0

看起來你可能會丟失一些庫。

-2

似乎無法定位諸如「clear_list」,「push」等功能的定義。查找包含這些定義的庫/對象/文件,然後驗證它們是否與您的應用程序正確鏈接。