473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

undefined reference to `main'

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.

Oct 6 '06 #1
8 52418

owolablo wrote:
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

Oct 6 '06 #2

owolablo wrote:
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

Oct 6 '06 #3
owolablo wrote:
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?
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 6 '06 #4
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!

Oct 6 '06 #5

owolablo wrote:
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!
Oct 6 '06 #6
owolablo wrote:
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.

Oct 6 '06 #7
owolablo wrote:
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

Oct 6 '06 #8
"Undefined reference to main" is actually a good sign because
it means you have no other fatal errors.

Steve
Oct 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
10
by: PCHOME | last post by:
Hi! Would someone please help me thess C error(in gcc on Linux)? The compiler continues to give me: readLP.o: In function `Input_Problem': readLP.o(.text+0x0): multiple definition of...
10
by: siroregano | last post by:
Hello- I've got a nice C program written that uses libsndfile (#include <sndfile.h>) to convert my raw data into a properly-formatted wav file. The program is composed of a single .c file that...
1
by: Andre Janssen | last post by:
Hi.... I tried to compile the following src with this command: "g++ -Wall -o bla alsaswitch.cpp". The src is an example src of xosd package. #include <xosd.h> int main (int argc, char...
8
by: wdh3rd | last post by:
I'm still new at C and can't solve this problem. I've looked through the FAQ and on the Web, but am not having luck. I'm getting an "undefined reference" error as well as a "Id returned 1 exit...
1
by: taiyang902 | last post by:
i program under linux ,and using kdevelop c/c++. the code follow, #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream> #include <cstdlib> using namespace std;
8
Motoma
by: Motoma | last post by:
Good evening everyone. I am starting to re-explore C++, and I wanted to build a singleton class. Unfortunately, when I set things up as I do in PHP, it doesn't work out for me. I hope that the...
2
by: zqiang320 | last post by:
Hello: I execute make ,then get error: $ make Making all in libsbml/src make: Entering directory `/home/internet/mydoc/test_pj/libsbml/src' ........ /bin/sh ./libtool --tag=CC --mode=link...
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.