gcc 编译时报错 "undefined reference to 'main'" , 如何解决?
写了一个很小的程序:
----------------------
#include <stdio.h>
main ()
{
printf ("HELLO WORLD!\n");
}
----------------------
用 %gcc -o test test.c 编译
没有问题,程序执行的结果也正确。
但使用 -d 选项编译时,gcc 报错
% gcc -d -o test tset.c
/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status
请各位大虾帮忙诊断一下这个问题如何解决?
----------------------
#include <stdio.h>
main ()
{
printf ("HELLO WORLD!\n");
}
----------------------
用 %gcc -o test test.c 编译
没有问题,程序执行的结果也正确。
但使用 -d 选项编译时,gcc 报错
% gcc -d -o test tset.c
/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status
请各位大虾帮忙诊断一下这个问题如何解决?
...全文
相关推荐
C语言中编译相关的常见错误
**缺失主函数错误**: 错误信息:“undefined reference to `main'”表明编译器在寻找程序的入口点`main`函数时未能找到。在C语言中,`main`函数是程序执行的起点。
dev-c-的使用方法汇总.doc
此外,如果收到“undefined reference to `WinMain@16'"的错误,可能是因为缺少main()函数定义,或者需要重新编译。
gcc makefile的应用
':/tmp/cc33Kydu.o(.text+0xe): undefined reference to `log'collect2: ld returned 1 exit status```这是因为`
LINUX下的C++编译器GCC简介
**未定义符号错误**: - 当遇到“undefined reference to 'xxxxx'”这样的错误时,通常是因为某个源文件中引用了未声明的函数或变量。
_dev-c-的使用方法汇总.doc
在连接后,可能会出现 undefined reference to `WinMain@16' 错误信息。这是因为没有定义 main() 函数,或者请重新编译。4.


