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

Recommended Answers

All 10 Replies

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

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 ?

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

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

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

Are you saying your complier is malfunctioning? It won't compile anything?

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

gcc -o server server.c

Does this server.c has main() function???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.