View Full Version : gcc compiler help

May 10th, 2011, 06:12 AM
Hi there,

When I try and compile a program through the terminal it says...

/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

Any help on how to fix this problem would be hugely appreciated. \

Tony Flury
May 10th, 2011, 06:54 AM
what is the command line that you use to compile your code ?

Does it happen with even the simplest program ?

Do you have build-essentials installed :

sudo apt-get install build-essential

May 10th, 2011, 07:12 AM
Its been working fine for the past month and its now doing this.

Yep, got the build essential and it does it with the simplest programs.

I usually just the ... gcc "file name" -o "output name" .... If that makes any sense. It's been working fine for months but now it doesn't.

Tony Flury
May 10th, 2011, 07:19 AM
can you post the simplest code snippet (something like Hello world) that recreates the problem.

The error is a linker problem (not the compiler) and it suggests that the module you are trying to compile does not have a "main" defined.

May 10th, 2011, 07:47 AM
#include <stdio.h>
int main()
printf(“Hello world.\n”);

Even something like that gives that response.

May 10th, 2011, 07:59 AM
Fixed the problem was just me doing something stupid!

Thanks all for your help though

Tony Flury
May 10th, 2011, 11:06 AM
What was the problem, you could help others ?

May 10th, 2011, 11:34 AM
It was actually me just consistently doing a typo the entire time, problem with the new keyboard.

Sorry didn't think it was necessary to post because it was purely my bad.

Tony Flury
May 10th, 2011, 12:22 PM
It happens - no worries. Glad you got it sorted :-)
I spent a couple of days at work isolating what i thought was bad code across 20 modules, which turned out to be a simple typo in our build system.

Did you want to mark this thread as Solved ?