undefined reference to `main'

O

owolablo

I'm making a project involving some C++ source files.
It keeps popping up the following error:

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

This happens whether I compile the code using a makefile or normally
(via a g++ command)
Anybody knows what this means?
Thanks.
 
T

Thomas Tutone

owolablo said:
I'm making a project involving some C++ source files.
It keeps popping up the following error:

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

This happens whether I compile the code using a makefile or normally
(via a g++ command)
Anybody knows what this means?
Thanks.

Probably that you have failed to include a definition of main.

If you have included such a definition, post it, and we can take a
look.

Best regards,

Tom
 
T

Thomas Tutone

owolablo said:
I'm making a project involving some C++ source files.
It keeps popping up the following error:

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

This happens whether I compile the code using a makefile or normally
(via a g++ command)
Anybody knows what this means?
Thanks.

Probably that you have failed to include a definition of main.

If you have included such a definition, post it, and we can take a
look.

Best regards,

Tom
 
V

Victor Bazarov

owolablo said:
I'm making a project involving some C++ source files.
It keeps popping up the following error:

/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
collect2: ld returned 1 exit status

This happens whether I compile the code using a makefile or normally
(via a g++ command)
Anybody knows what this means?

It means your linker tries to link your program and cannot find the
'main' function, which every program _must_ have. Don't ask your
linker to link if you only compile a single translation unit. See the
-c command-line switch. And next time g++-specific questions should
be asked in gnu.g++.help.

V
 
O

owolablo

I have actually included a definition to main.My project has two source
files and the main functions in both of them are as follows:

int main (int argc, char *argv[])
{
if(argc<3){
ACE_DEBUG((LM_DEBUG,"Usage %s <hostname> <port_number>\n",
argv[0]));
ACE_OS::exit(1);
}
Client client(argv[1],ACE_OS::atoi(argv[2]));
client.connect_to_server();
client.send_to_server();
return 0;
}

and the other one is:

int main (int argc, char *argv[])
{
if(argc<3){
ACE_DEBUG((LM_DEBUG,"Usage %s <hostname> <port_number>\n",
argv[0]));
ACE_OS::exit(1);
}
Client client(argv[1],ACE_OS::atoi(argv[2]));
client.connect_to_server();
client.send_to_server();
return 0;
}

Thank you!
 
J

jjds101

owolablo said:
I have actually included a definition to main.My project has two source
files and the main functions in both of them are as follows:
And perhaps therin lies the problem. You probably don't want to link 2
main functions together. How does the linker know which one to use as
the entry point?



int main (int argc, char *argv[])
{
if(argc<3){
ACE_DEBUG((LM_DEBUG,"Usage %s <hostname> <port_number>\n",
argv[0]));
ACE_OS::exit(1);
}
Client client(argv[1],ACE_OS::atoi(argv[2]));
client.connect_to_server();
client.send_to_server();
return 0;
}

and the other one is:

int main (int argc, char *argv[])
{
if(argc<3){
ACE_DEBUG((LM_DEBUG,"Usage %s <hostname> <port_number>\n",
argv[0]));
ACE_OS::exit(1);
}
Client client(argv[1],ACE_OS::atoi(argv[2]));
client.connect_to_server();
client.send_to_server();
return 0;
}

Thank you!
 
R

Ron Natalie

owolablo said:
I have actually included a definition to main.My project has two source
files and the main functions in both of them are as follows:

You are only allowed ONE main definition.

If you are writing C++ make sure you are using g++ to
link rather than gcc.
 
P

Puppet_Sock

owolablo said:
I have actually included a definition to main.My project has two source
files and the main functions in both of them are as follows:
[snip two definitions of main]

You need to quote enough of the post you are responding
to for people to know what it is you are talking about. In
many cases, the previous post may not be available to
people reading your post.

Your problem would seem to be that you have multiple
executables in the same project, and that one or more of
them does not have a main.

You must have exactly one main per executable.

How you get that in a project is not on topic here, as it is
to do with the details of your development platform. It
would be better if you ask such questions in a forum related
to your specific development platform.
Socks
 
S

Steve Pope

"Undefined reference to main" is actually a good sign because
it means you have no other fatal errors.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top