473,588 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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+0x 18): 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 52434

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+0x 18): 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+0x 18): 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+0x 18): 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_D EBUG,"Usage %s <hostname<port_ number>\n",
argv[0]));
ACE_OS::exit(1) ;
}
Client client(argv[1],ACE_OS::atoi(a rgv[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_D EBUG,"Usage %s <hostname<port_ number>\n",
argv[0]));
ACE_OS::exit(1) ;
}
Client client(argv[1],ACE_OS::atoi(a rgv[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_D EBUG,"Usage %s <hostname<port_ number>\n",
argv[0]));
ACE_OS::exit(1) ;
}
Client client(argv[1],ACE_OS::atoi(a rgv[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_D EBUG,"Usage %s <hostname<port_ number>\n",
argv[0]));
ACE_OS::exit(1) ;
}
Client client(argv[1],ACE_OS::atoi(a rgv[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
3137
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
31065
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 joy. I got dev-c++ and a bit of winsock sample code. I've done nothing out of the ordinary. I could only assume that anyone else that downloaded this software and attempted this would meet with the same result. The problem lies with either the...
10
5487
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 `Input_Problem' main.o(.text+0x2f2): first defined here /usr/bin/ld: Warning: size of symbol `Input_Problem' changed from 172 to 185 in
10
21078
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 compiles without error under gnu/linux. Unfortunately, when ld tries to link the file, I get the following: bash> gcc -Wall -D_GNU_SOURCE wavconvert.c -o wavconvert
1
4282
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 *argv) { xosd *osd;
8
5611
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 status" error. I've pared down the code to a simple example: ---------------------------------square.c ---------------------------------------------------
1
10899
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
6280
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 problem is something small and obvious, but here is what I have: #include <iostream> using namespace std; class ClientManager {
2
6217
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 gcc -g -O2 -o test test.o libsbml/src/libsbml.la -lsbml -lstdc++ -lm
3
35712
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?. Main.cpp:377: undefined reference to `operator delete(void*)' tinyXML/include/tinystr.h:259: undefined reference to `operator delete(void*)' ../common/tinyXML/include/tinyxml.h:1401: undefined reference to `operator delete(void*)'...
0
7927
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8220
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8222
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6632
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5723
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1457
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.