对main 未定义的引用_错误:ID返回1个退出状态(对“ main”的未定义引用)

对main 未定义的引用

As we know that,

我们知道

  1. Each program must have a main() function, compiler starts execution from the main() function – main() is an entry point to the program,

    每个程序必须具有main()函数,编译器从main()函数开始执行-main()是程序的入口点,

  2. And, the second this “C language is a case-sensitive language – uppercase words, and lowercase words are different”.

    并且,第二种是“ C语言是区分大小写的语言-大写单词和小写单词不同”

This error is occurred on following cases,

在以下情况下会发生此错误,

  1. If main() is not written in lowercase, like you used Main(), MAIN(), mAin() or anything else.

    如果main()不是用小写字母编写的,就像您使用Main() , MAIN() , mAin()或其他任何东西一样。

  2. If main() does not exist in the program or by mistake you mistyped the main().

    如果程序中不存在main()或错误地键入了main() 。

Consider the programs…

考虑程序…

Program 1) ‘main()’ is not in lowercase

程序1)’main()’不是小写

#include <stdio.h>

int Main(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

Program 2) Mistyped ‘main()’ as ‘nain()’ or anything else

程序2)将’main()’输入为’nain()’或其他任何东西

#include <stdio.h>

int nain(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 – use correct syntax of main() i.e. use main(), type correct spelling in lowercase

要解决此错误-使用main()的正确语法,即使用main() ,用小写字母输入正确的拼写

Correct code:

正确的代码:

#include <stdio.h>

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

Output

输出量

Hello world!


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

对main 未定义的引用

    原文作者:cumubi7453
    原文地址: https://blog.csdn.net/cumubi7453/article/details/107803144
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞