GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-May-2008, 13:30
Mrehman Mrehman is offline
New Member
 
Join Date: Mar 2008
Posts: 23
Mrehman is on a distinguished road
Question

Error LNK2005: _main already defined in


hey guyz how's it going? alright the thing is i am working on structs, i think i have finished the code. when i compile it i don't have any errors but 4 warnings which i don't understand. following that when i run the program it gives me 2 errors. they are common and i searched for them on Google. i saw lot of them but didn't know where was i making error, and how should i fix it. this is what the code suppose to do
Create 2 instances of the Struct
1st Instance is underneath and 2nd is suppose to be ours.

Mr.
Lupoli
18005557878
1600 Pennsylvania Ave.
Washington
D.C.
20001
my code is
CPP / C++ / C Code:
# include <iostream>
# include <string>
using namespace std;
struct BIO
{
	string Fname;
	string Lname;
	int Tele;
	string Str_add;
	string Town;
	string State;
	int Zip;
};	

void main()
{
	cout<<"here's Mr. Lupoli's Info"<<endl;
	BIO Lupoli= {"Mr.","Lupoli",18005557878,"1600 Pennsylvania Ave","Washington","D.C.",20001};
	cout<<"END OF INSTANCE"<<endl;
	cout<<"Here's My Info"<<endl;
	BIO Mateen = {"Mateen","Rehman", 4434556786, "9351 Owings Choice Ct", "Owings Mills", "Maryland", 21117};
	cout<<"END OF INSTANCE"<<endl;
} 
sorry that i use void main instead of int main.
my errors are 1>------ Build started: Project: Struct, Configuration: Debug Win32 ------
1>Linking...
1>Struct.obj : error LNK2005: _main already defined in Struct 2.obj
1>C:\Users\Amateen\Documents\Visual Studio 2005\Projects\Struct\Debug\Struct.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://c:\Users\Amateen\Documents\Visual Studio 2005\Projects\Struct\Struct\Debug\BuildLog.htm"
1>Struct - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
how should i fix the problem. THANKS in Advance
  #2  
Old 03-May-2008, 15:24
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,310
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 behold

Re: need assisstance fixing an error


Quote:
Originally Posted by Mrehman
sorry that i use void main instead of int main.
Then why do you use it? Does your instructor require it or what? My compiler won't accept it, so I have to change your program before compiling it. (That's not a big deal for me, but I just wonder...)

Quote:
Originally Posted by Mrehman
...4 warnings which i don't understand...
Then why don't you tell us what they are; maybe someone can help you. See footnote.
I mean, I wouldn't even dream of trying to run a program of mine unless I understood every stinkin' thing that the compiler tried to tell me. I would then do whatever I reasonably could to get a clean compile. (But, that's just me: I'm funny that way.)
Quote:
Originally Posted by Mrehman
f
my errors are 1>------ Build started: Project: Struct, Configuration: Debug Win32 ------
1>Linking...
1>Struct.obj : error LNK2005: _main already defined in Struct 2.obj
1>C:\Users\Amateen\Documents\Visual Studio 2005\Projects\Struct\Debug\Struct.exe : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://c:\Users\Amateen\Documents\Visual Studio 2005\Projects\Struct\Struct\Debug\BuildLog.htm"
1>Struct - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
how should i fix the problem.

How many source files are in your project? How many of them have a main() function? How many main() functions can a program have? Why do you need anything more than the file that you showed?

Regards,

Dave

Footnote: Both of the numbers in your initializers for Tele can't be held in 32-bit integers (which is what most systems have these days). These lines cause my compiler to generate error messages (and no executable is created). I guess it's possible that some compilers just give warnings here (and if they do, then it's pretty much a sure thing that they won't store the value that you are trying to giv it).

Maybe the Tele should be a string also??? Or, to put it another way: Is there any reason why it couldn't be a string?
  #3  
Old 03-May-2008, 15:53
Mrehman Mrehman is offline
New Member
 
Join Date: Mar 2008
Posts: 23
Mrehman is on a distinguished road

Re: need assisstance fixing an error


i have 2 source files. struct 1 and struct 2. my warnings are
1>c:\users\amateen\documents\visual studio 2005\projects\struct\struct\struct 2.cpp(1 : warning C4305: 'initializing' : truncation from '__int64' to 'int'
1>c:\users\amateen\documents\visual studio 2005\projects\struct\struct\struct 2.cpp(1 : warning C4309: 'initializing' : truncation of constant value
1>c:\users\amateen\documents\visual studio 2005\projects\struct\struct\struct 2.cpp(21) : warning C4305: 'initializing' : truncation from '__int64' to 'int'
1>c:\users\amateen\documents\visual studio 2005\projects\struct\struct\struct 2.cpp(21) : warning C4309: 'initializing' : truncation of constant value
tell me if you need more.
  #4  
Old 03-May-2008, 21:25
Mrehman Mrehman is offline
New Member
 
Join Date: Mar 2008
Posts: 23
Mrehman is on a distinguished road

Re: need assisstance fixing an error


i figured it out thanks
 
 

Recent GIDBlogNot selected for officer school by crystalattice

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
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Linked Lists advice request promsan C Programming Language 74 23-May-2007 08:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:58.


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