0

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

3
Contributors
10
Replies
12
Views
6 Years
Discussion Span
Last Post by sree_ec
0

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 by bufospro: n/a

0

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 by gerard4143: n/a

0

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

Edited by bufospro: n/a

0

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?

0

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

0

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?

0

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

gcc -o server server.c

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.