Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » C programs » Common C program Errors

Error: Id returned 1 exit status (undefined reference to 'main')



Here, we are going to learn why an Error: Id returned 1 exit status (undefined reference to 'main') occurs and how to fixed in C programming language?
Submitted by IncludeHelp, on September 11, 2018

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,
  2. And, the second this "C language is a case-sensitive language - uppercase words, and lowercase words are different".

This error is occurred on following cases,

  1. If main() is not written in lowercase, like you used Main(), MAIN(), mAin() or anything else.
  2. If main() does not exist in the program or by mistake you mistyped the main().

Consider the programs...

Program 1) 'main()' is not in lowercase

#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

#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

Correct code:

#include <stdio.h>

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

Output

Hello world!





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.