我尝试使用下面的命令对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
我尝试使用下面的命令对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
看来,你有没有在你的hello.c
定义的main()
功能。正确的代码是这样的:
#include <stdio.h>
int main(int argc, char**argv) /// <<==-- here is a correct definition
{
printf("Whatever you want\n");
return 0;
}
了'return'缺失和参数是不是强制性的。 –
给出的参数表明它们是如何定义的。 – osgx
当然,只是想提一提,他们并不是真正需要的。特别是对于以'Hello world'开头的初学者程序员来说,他们可能有点混乱,有时候:)无论如何+1,因为我会写同样的东西。 –
请,加入hello.c中的文本到您的文章 – osgx