2011-07-30 29 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,因为我会写同样的东西。 –