2011-07-30 35 views
0

我嘗試使用下面的命令對gcc在centos中主錯誤的未定義引用。

gcc hello.c 

運行用gcc一個Hello World程序,但我收到以下錯誤。

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start': 
(.text+0x18): undefined reference to `main' 
collect2: ld returned 1 exit status 
+2

請,加入hello.c中的文本到您的文章 – osgx

回答

1

看來,你有沒有在你的hello.c定義的main()功能。正確的代碼是這樣的:

#include <stdio.h> 

int main(int argc, char**argv) /// <<==-- here is a correct definition 
{ 
    printf("Whatever you want\n"); 
    return 0; 
} 
+0

了'return'缺失和參數是不是強制性的。 –

+0

給出的參數表明它們是如何定義的。 – osgx

+0

當然,只是想提一提,他們並不是真正需要的。特別是對於以'Hello world'開頭的初學者程序員來說,他們可能有點混亂,有時候:)無論如何+1,因爲我會寫同樣的東西。 –