GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Jan-2006, 18:45
thunderdome thunderdome is offline
New Member
 
Join Date: Jan 2006
Posts: 4
thunderdome is on a distinguished road
Arrow

Error: Multiple definition of '_main'...


HI,
As u may think, I am new to C programing and as I was making programs in C, my first program was successfully compiled while all the programs that followed contained load of errors; the main being
<<Error: Multiple definition of '_main'>>
I think that the first program that was compiled has a 'main' that links with all the other programs that I want to create.
Can anyone tell me what is the way out for creating other programs without this error??
By the way, I am using DJGPP's C compiler on a win98 PC.
Is there something that I have to change the properties anywhere??
Any help appreciated.
  #2  
Old 19-Jan-2006, 18:58
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Error: Multiple definition of '_main'...


Quote:
Originally Posted by thunderdome
HI,
all the programs that followed contained load of errors; the main being
<<Error: Multiple definition of '_main'>>
I think that the first program that was compiled has a 'main' that links with all the other programs that I want to create.

A program can only have one "main()" function (that is where execution starts), therefore you can't link together different source files that contain more than one "main()" function.

Maybe you could give us an idea of what you are trying to do with your program(s). Be specific.

Regards,

Dave
  #3  
Old 19-Jan-2006, 19:08
thunderdome thunderdome is offline
New Member
 
Join Date: Jan 2006
Posts: 4
thunderdome is on a distinguished road

Re: Error: Multiple definition of '_main'...


As I am new to C programing, I dont know about the linking of the *.c files. What I mean to say is that first I made my first C program named 'HelloWorld.c' and next I wanted to make another C program relating to addition of 2 numbers <add.c>.
Now, HelloWorld.c runs perfectly without errors, but the other programs that I want to write, are not compiled properly and are with loads of errors that I don't think have any.
i.e. add.c when compiled says:::
Error: Multiple definition of '_main' with other errors following it.
When I point to this error, the DJGPP program takes me back to the 'main' statement I wrote in HelloWorld.c .
  #4  
Old 19-Jan-2006, 23:06
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: Error: Multiple definition of '_main'...


Did you simply add the code for add.c to the same project as HelloWorld.c? If so, you can't. Create a new project.

Also:
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
  #5  
Old 20-Jan-2006, 02:30
thunderdome thunderdome is offline
New Member
 
Join Date: Jan 2006
Posts: 4
thunderdome is on a distinguished road

Re: Error: Multiple definition of '_main'...


I think I found the problem.
In my computer, DJGPP considers all the .c programs written one after the other are read as a single project that does not require the repetitive codes such as 'main'...
However, I do not know how to make single programs work as their own entity and not as a whole project.
So, now I am using Turbo C which does not have the same facility (/annoyance).
Thanks for your replies.
  #6  
Old 23-Jan-2006, 00:45
thunderdome thunderdome is offline
New Member
 
Join Date: Jan 2006
Posts: 4
thunderdome is on a distinguished road

Re: Error: Multiple definition of '_main'...


hello all again,
I was just surfing the web when I came up to a forum that replied to me that << DJGPP compiles all open files into one exe, even if you don't have a project open. Close your other file[s] and it will compile just fine.>>
I seached all the menus in DJGPP and found that the close button was located on Windows menu (shortcut Alt+F3). But then again whenever now I try to run any new programs in c the rhide hangs itself up without showing any result screen. May be because of some insufficient memory.
Anyway now I use Borland to peacefully type the programs. I was suggested that there are other ''compilers'' such as gvim and xterm (editors) which are good.
Thanks all for their time and replies.

DJGPP is much better than Turbo C as I was suggested. So folks out there, plz use a modern compiler rather than making a mistake that I made.
  #7  
Old 08-Feb-2006, 02:03
realnapster realnapster is offline
Awaiting Email Confirmation
 
Join Date: Feb 2006
Posts: 51
realnapster will become famous soon enough

Re: Error: Multiple definition of '_main'...


As you are a beginner please don't be afraid it usually happens with all but please remember to follow these steps whnever you write a program::
1.always write code for each program in new window.
2.first compile and then run it
3.use tracing methods to know what's going on it means like in my compiler of turboc f7 key is used to trace the logic find some help in ya complier.

And finally if ya really need some help then please post your code alongwith the error because nobody can help without having a look at the code i think now u r gonna follow them.

best of luck for your future programming in c and always feel free in asking questions because many masters of c are out here don't think that i am master i m just a napster
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to initialize an array in a class definition or in constructor? pablowablo C++ Forum 17 05-Sep-2009 12:14
function definition and declaration dox C Programming Language 4 14-Jul-2005 11:03
type definition kobi_hikri C++ Forum 3 08-Jun-2005 18:10
Error - unresolved external symbol _WinMain ap6118 C++ Forum 6 23-Mar-2005 23:46
Another definition of a mirror site jrobbio Open Discussion Forum 0 21-Jul-2003 01:44

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:27.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.