未定义引用centos上gcc中的主要错误。

时间:2011-07-30 08:54:55

标签: gcc reference undefined main

我正在尝试使用以下命令使用gcc运行hello world程序

gcc hello.c

但是我收到以下错误。

/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

1 个答案:

答案 0 :(得分:1)

似乎您在main()中没有定义hello.c功能。正确的代码是这样的:

#include <stdio.h>

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