Q:

Error: undefined reference to \'main\' in C

belongs to collection: C Common Errors Programs

0

Error: undefined reference to 'main' in C

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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?

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!

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Error: missing terminating double quote character ... >>