Home »
C programs »
C common errors programs
Error: undefined reference to 'main' in C
Here, we will learn why an error: undefined reference to 'main' occurs and how to fix it in C programming language?
By IncludeHelp Last updated : March 10, 2024
Error: undefined reference to '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.
Consider the given example, here I wrote mian() instead of main(), see the spelling of main() which is not correct in the program.
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 - Error: undefined reference to 'main'
To fix this error, correct the spelling of the main() function.
Correct Code
#include <stdio.h>
int main(void) {
printf("Hello world!");
return 0;
}
Output
Hello world!
C Common Errors Programs »