Hi, I have a problem with my code in C
An error occurs with message :

/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../lib64/crt1.o(.text+0x21): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status


Does anyone know for it ?

Thanks a lot

Sounds like your code doesn't have a main function...Could you post the code and the compile line.

Unfortunately I can't write here all the code from project.
Do you believe that I have forgot a '{' '}' character ?

Edited 6 Years Ago by bufospro: n/a

Unfortunately I can't write here all the code from project.
Do you believe that I have forgot a '{' '}' character ?

That shouldn't generate the error you have...The error could be two things, it could be that the compiler can't find main or that it's finding two mains or _start places in your code.

An example

test.c

#include <stdio.h>

void myfunc(void)
{
	fputs("Hello, World!\n", stdout);
}

If I try and compile this code like so

gcc test.c -o test

It'll produce the error you had because its trying to create an executable but can't find the _start function main.

Are you sure you should be compiling to an object file say test.o

gcc -c test.c

Edited 6 Years Ago by gerard4143: n/a

My code has main function one time.
I don't know sometimes C make me nervous.

Edited 6 Years Ago by bufospro: n/a

My code has main function one time.
I don't know sometimes C make me nervous.

If that's the case your {} error may have thrown off the code parser and as a result generated the _start error...Its working now right?

If that's the case your {} error may have thrown off the code parser and as a result generated the _start error...Its working now right?

It's problem from the server's compiler you said.
I tried hello world program and the same message appears.

Thanks a lot for our help

It's problem from the server's compiler you said.
I tried hello world program and the same message appears.

Thanks a lot for our help

Which compiler are you using?
Can you paste the Command used to compile your code here?

Which compiler are you using?
Can you paste the Command used to compile your code here?

gcc -o server server.c

This article has been dead for over six months. Start a new discussion instead.