对main 未定义的引用_错误:在C中未定义对“ main”的引用

本文详细解析了C程序中常见的“main”未定义引用错误,通常由main函数拼写错误引起。通过一个实例,展示了如何通过修正main函数的拼写来解决这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对main 未定义的引用

The error: undefined reference to 'main' in C program is a very stupid mistake by the programmer, it occurs when the main() function does not exist in the program. If you used main() function and still the error is there, you must check the spelling of the main() function.

错误:程序员在C程序中对“ main”的未定义引用是一个非常愚蠢的错误,当main()函数在程序中不存在时发生。 如果使用main()函数,但仍然存在错误,则必须检查main()函数的拼写。

Consider the given example, here I wrote mian() instead of main(), see the spelling of main() which is not correct in the program.

考虑给出的例子,在这里我写勉()而不是main()中 ,见)的主要拼写(这是不是在程序正确。

Example:

例:

#include <stdio.h>

int mian(void) {
	printf("Hello world!");
	return 0;
}

Output

输出量

/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function '_start':
(.text+0x20): undefined reference to 'main'
collect2: error: ld returned 1 exit status

How to fix?

怎么修?

To fix this error, correct the spelling of the main() function.

要解决此错误,请更正main()函数的拼写。

Correct code:

正确的代码:

#include <stdio.h>

int main(void) {
	printf("Hello world!");
	return 0;
}

Output

输出量

Hello world!

翻译自: https://www.includehelp.com/c-programs/undefined-reference-to-main-error-in-c.aspx

对main 未定义的引用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值