error LNK2005: _main already defined<p><font face="Times New Roman, Times, Serif">I recently installed VC++ 2005 EXP edition.</font></p> <p><font face="Times New Roman">1) I created a project name Radius and created two new items hello.cpp and area.cpp.</font></p> <p><font face="Times New Roman">2) area.cpp is the first item and hello.cpp is the second one. </font></p> <p><font face="Times New Roman">3) When I build the project Radius, I got the error</font></p><font face="Times New Roman"><font size=1> <p>LNK2005: _main already defined in area.obj</p> <p><font face="Times New Roman, Times, Serif" size=3>Can you guide me to fix the compilation error.</font></p> <p><font face="Times New Roman" size=3>Thanks GKW82</font></p></font></font>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Zcf3b6326-6e58-4b85-afb1-2694a1450128http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#cf3b6326-6e58-4b85-afb1-2694a1450128http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#cf3b6326-6e58-4b85-afb1-2694a1450128GKW82http://social.msdn.microsoft.com/Profile/en-US/?user=GKW82error LNK2005: _main already defined<p><font face="Times New Roman, Times, Serif">I recently installed VC++ 2005 EXP edition.</font></p> <p><font face="Times New Roman">1) I created a project name Radius and created two new items hello.cpp and area.cpp.</font></p> <p><font face="Times New Roman">2) area.cpp is the first item and hello.cpp is the second one. </font></p> <p><font face="Times New Roman">3) When I build the project Radius, I got the error</font></p><font face="Times New Roman"><font size=1> <p>LNK2005: _main already defined in area.obj</p> <p><font face="Times New Roman, Times, Serif" size=3>Can you guide me to fix the compilation error.</font></p> <p><font face="Times New Roman" size=3>Thanks GKW82</font></p></font></font>Tue, 04 Jul 2006 04:08:33 Z2006-07-05T17:02:54Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#aeb93196-6cdd-49a6-bf9d-b4e7188ae5bfhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#aeb93196-6cdd-49a6-bf9d-b4e7188ae5bfcythehttp://social.msdn.microsoft.com/Profile/en-US/?user=cytheerror LNK2005: _main already defined<p>This error is because of multiple definitions of main. You must have defined main in area.cpp as well as in hello.cpp. In C/C++ programs, you can write only one main per application.</p> <p>Remove one definition of main and it should work fine.</p> <p>Cheers </p>Tue, 04 Jul 2006 05:37:04 Z2006-07-05T17:02:54Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#490d4ece-bd2a-4455-aa34-eee559e4e1e6http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#490d4ece-bd2a-4455-aa34-eee559e4e1e6GKW82http://social.msdn.microsoft.com/Profile/en-US/?user=GKW82error LNK2005: _main already defined<p><font face="Times New Roman, Times, Serif">Yes. I defined main() in both. I removed the main from hello and </font><font face="Times New Roman, Times, Serif">I am now getting the error </font></p><font size=1> <p>hello.cpp(4) : error C2447: '{' : missing function header (old-style formal list?)</p> <p>GKW82</p></font>Wed, 05 Jul 2006 23:26:45 Z2006-07-05T23:26:45Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#1e1efa16-bf1a-49cc-8df8-7ede4e822a7ehttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#1e1efa16-bf1a-49cc-8df8-7ede4e822a7e郭郭http://social.msdn.microsoft.com/Profile/en-US/?user=%u90ed%u90ederror LNK2005: _main already defined<p>Delete area.cpp and creat it.</p> <p>Do the thing above.</p>Thu, 06 Jul 2006 01:39:49 Z2006-07-06T01:39:49Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#912ad009-6d12-4085-a7dc-72b145940416http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#912ad009-6d12-4085-a7dc-72b145940416GKW82http://social.msdn.microsoft.com/Profile/en-US/?user=GKW82error LNK2005: _main already defined<p><font face="Times New Roman, Times, Serif">Nope.. didn't work. Getting the same error.</font></p> <p><font face="Times New Roman">GKW82</font></p>Thu, 06 Jul 2006 04:06:49 Z2006-07-06T04:06:49Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#31be9f63-854a-49ed-9040-2e858fd28265http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#31be9f63-854a-49ed-9040-2e858fd28265Sunil_Dhttp://social.msdn.microsoft.com/Profile/en-US/?user=Sunil_Derror LNK2005: _main already definedPls. paste the hello.cpp codeThu, 06 Jul 2006 05:24:30 Z2006-07-06T05:24:30Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#d3fff8a3-b33b-47b6-9a33-8d3c4e5891cfhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#d3fff8a3-b33b-47b6-9a33-8d3c4e5891cfcythehttp://social.msdn.microsoft.com/Profile/en-US/?user=cytheerror LNK2005: _main already defined<div class=section id=errorTitleSection> <h4 class=subHeading>This is what MSDN says : </h4> <h4 class=subHeading>Error Message </h4><em>'{' : missing function header (old-style formal list?)<br></em> <p></p></div> <p><em>An open brace occurs at global scope without a corresponding function header.</em></p> <p><em>This error can be caused by an old-style C-language formal list.</em></p> <p><em>The following sample generates C2447:</em></p> <p><em>int c;<br>{}       // C2447</em></p> <p>Check whether you are writing the open brace without the function name.</p> <p>Else post the code.</p>Thu, 06 Jul 2006 06:24:27 Z2006-07-06T06:24:27Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#9bbec796-289f-4115-b23d-2fb4b61a11b5http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#9bbec796-289f-4115-b23d-2fb4b61a11b5GKW82http://social.msdn.microsoft.com/Profile/en-US/?user=GKW82error LNK2005: _main already defined<p><font face="Times New Roman, Times, Serif">Here is the piece of code.</font></p> <p><font face="Times New Roman">1) radius.cpp</font></p><font color="#0000ff" size=2> <p>#include</font><font size=2> </font><font color="#800000" size=2>&lt;iostream&gt;</font></p> <p><font color="#008000" size=2>/* program to calculate radius of a circle */</p></font><font color="#0000ff" size=2> <p>void</font><font size=2> main()</p> <p>{</p> <p></font><font color="#0000ff" size=2>float</font><font size=2> area, radius;</p> <p></p> <p>printf(</font><font color="#800000" size=2>&quot;Radius = ? &quot;</font><font size=2>);</p> <p>scanf(</font><font color="#800000" size=2>&quot;%f&quot;</font><font size=2>, &amp;radius);</p> <p>area = 3.14159 * radius * radius;</p> <p>printf(</font><font color="#800000" size=2>&quot;Area = %f&quot;</font><font size=2>, area);</p> <p>}</p></font> <p><font face="Times New Roman">2) hell.cpp</font></p><font color="#0000ff" size=2> <p>include</font><font size=2> </font><font color="#800000" size=2>&lt;iostream&gt;</p></font><font size=2> <p>{</p> <p>printf(</font><font color="#800000" size=2>&quot;Hello world\n&quot;</font><font size=2>);</p></font> <p><font size=2></p> <p></p> <p>}</p><font size=1> <p>c:\documents and settings\owner\my documents\visual studio 2005\projects\radius\radius\hello.cpp(4) : error C2447: '{' : missing function header (old-style formal list?)</p></font></font> <p><font size=2>GKW82</p></font>Fri, 07 Jul 2006 16:49:08 Z2006-07-07T16:49:08Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#83e6386d-4812-44d8-92d4-517ebe71deb8http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#83e6386d-4812-44d8-92d4-517ebe71deb8James Kellyhttp://social.msdn.microsoft.com/Profile/en-US/?user=James%20Kellyerror LNK2005: _main already defined<p><font face="Times New Roman">Try the following....</font></p> <p><font face="Times New Roman">1) radius.cpp</font></p> <p><font color="#0000ff" size=2>#include</font><font size=2> </font><font color="#800000" size=2>&lt;iostream&gt;</font></p> <p><font color="#008000" size=2>/* program to calculate radius of a circle */</p></font><font color="#0000ff" size=2> <p>void</font><font size=2> main() </font></p> <p><font size=2>{</font></p> <p><font size=2>   <font color="#0000ff">float</font> area, radius;</font></p> <p><font size=2></font></p> <p><font size=2>   printf(<font color="#800000">&quot;Radius = ? &quot;</font>);</font></p> <p><font size=2>   scanf(<font color="#800000">&quot;%f&quot;</font>, &amp;radius);</font></p> <p><font size=2>   area = 3.14159 * radius * radius;</font></p> <p><font size=2>   printf(<font color="#800000">&quot;Area = %f&quot;</font>, area);</font></p> <p><font size=2>}</font></p> <p><font face="Times New Roman">2) hell.cpp</font></p><font color="#0000ff" size=2> <p>include</font><font size=2> </font><font color="#800000" size=2>&lt;iostream&gt;</p></font><font size=2> <p><font color="#3366ff">void </font>function_name() <font color="#339966"> // &lt;---------------------------- did you miss this out?</font></p> <p>{</p> <p>   printf(</font><font color="#800000" size=2>&quot;Hello world\n&quot;</font><font size=2>);</p></font> <p><font size=2></p> <p></p> <p>}</p></font>Fri, 07 Jul 2006 17:59:59 Z2006-07-07T17:59:59Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#3684d319-4c5b-47a3-b5e8-c9f955a5aed6http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#3684d319-4c5b-47a3-b5e8-c9f955a5aed6GKW82http://social.msdn.microsoft.com/Profile/en-US/?user=GKW82error LNK2005: _main already defined<p><font face="Times New Roman, Times, Serif">The whole problem starts when I include the function main() in the hello.cpp. I end up in getting the message</font></p><font size=1> <p>error LNK2005: _main already defined in hello.obj</p></font> <p><font face="Times New Roman">GKW82.</font></p> <p><font face="Times New Roman"></font> </p> <p><font face="Times New Roman"></font> </p>Fri, 07 Jul 2006 23:46:33 Z2006-07-07T23:46:33Zhttp://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#68d83c9e-fa08-469b-9227-e7b7bbced1b1http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/cf3b6326-6e58-4b85-afb1-2694a1450128#68d83c9e-fa08-469b-9227-e7b7bbced1b1James Kellyhttp://social.msdn.microsoft.com/Profile/en-US/?user=James%20Kellyerror LNK2005: _main already defined<p>I think what you are trying to do is....</p> <p> <hr id="[object]"> <p></p> <p>1.) File: hello.cpp</p><pre>#include &lt;IOSTREAM&gt; #include &lt;RADIUS.H&gt; int main(int argc, char *argv[]) { float area = get_area(5); printf(&quot;Area of circle with radius %d = %f\n&quot;, 5, area); } </pre> <p>2.) File: radius.h</p><pre>float get_area(float radius); float get_circumference(float radius); </pre> <p>3.) File: radius.cpp</p><pre>#include &lt;RADIUS.H&gt; float get_area(float radius) { return (3.14159 * radius * radius); } float get_circumference(float radius) { return (3.14159 * (radius * 2)); } </pre>Sat, 08 Jul 2006 15:37:54 Z2006-07-08T15:37:54Z