对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 未定义的引用

Logo

鸿蒙生态一站式服务平台。

更多推荐