<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>undefined reference to &#39;WinMain@16&#39;</title>
		<link>http://www.allegro.cc/forums/view/596872</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 02 Jul 2008 14:46:25 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just seeing if someone here could help me out. I&#39;ve been trying to set up code::blocks with allegro and got it to run, but I don&#39;t think it&#39;s right. The book that I&#39;m reading on allegro gives a test program to see if allegro is working right.</p><p>#include &lt;conio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &quot;allegro.h&quot;</p><p>#include &lt;conio.h&gt;<br />#include &lt;stdlib.h&gt;<br />#include &quot;allegro.h&quot;</p><p>int main()<br />{<br />    allegro_init();<br />    printf(&quot;Allegro version = %s\n&quot;, allegro_id);<br />    printf(&quot;\nPress any key...\n&quot;);<br />    getch();<br />    return 0;<br />}<br />END_OF_MAIN;</p><p>This, however, gives a &#39;undefined reference to WinMain@16&#39; linker error. So I changed main to WinMain and it compiles and runs fine. I was wandering if coding it with the WinMain ruins the crossplatforminess of allegro and if it does, why does it try to use WinMain as a entry point.</p><p>using vista, Allegro 4.2.1, mingw 3.4.5, and the gcc compiler with Code::Blocks nightly build</p><p>||=== allgtest, Debug ===|<br />C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c||In function `_mangled_main&#39;:|<br />C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c|8|warning: implicit declaration of function `printf&#39;|<br />C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c|13|warning: type defaults to `int&#39; in declaration of `END_OF_MAIN&#39;|<br />C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c|13|warning: data definition has no type or storage class|<br />\mingw\lib\libmingw32.a(main.o):main.c:(.text+0x106)||undefined reference to `WinMain@16&#39;|<br />||=== Build finished: 1 errors, 3 warnings ===|
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (levizil)</author>
		<pubDate>Sun, 29 Jun 2008 02:07:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The book that I&#39;m reading on allegro gives a test program to see if allegro is working right.
</p></div></div><p>
The book you&#39;re reading has known bugs and problems, so beware.</p><p>Anyway, it&#39;s END_OF_MAIN(), not END_OF_MAIN; (or END_OF_MAIN(); for that matter).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I was w<b>o</b>ndering if coding it with the WinMain ruins the crossplatforminess of allegro
</p></div></div><p>
Yes, it does.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
and if it does, why does it try to use WinMain as a entry point.
</p></div></div><p>
You have to, if you want to write a Windows GUI application (blame Microsoft). Allegro uses a trick that allows you to write a regular main() function instead of WinMain (if you want the details: through END_OF_MAIN() Allegro defines a WinMain function that calls your main() function).</p><p>EDIT: other problems associated with that book: conio.h and any functions defined by it. Avoid these like teh plague, they&#39;re <i>not</i> portable and <i>cannot</i> (and most definately shouldn&#39;t) be used reliably alongside Allegro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 29 Jun 2008 02:26:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for responding. I put the () in the end of main and it works now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (levizil)</author>
		<pubDate>Sun, 29 Jun 2008 03:34:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think you really need WinMain to get a Windows GUI app.  A regular main is ok.  To disable the console window, you add &quot;subsystem:windows&quot; to the linker&#39;s command line.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sun, 29 Jun 2008 03:43:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you add &#39;subsystem:windows&#39;, the linker will search for WinMain as the application&#39;s entry point, methinks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Sun, 29 Jun 2008 14:52:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If I&#39;m not mistaken, &quot;Undefined reference to WinMain@16&quot; is just Mingw&#39;s way to report that the linker didn&#39;t find main (or WinMain). (If it is not there, how&#39;s it supposed to know which it should be.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (anonymous)</author>
		<pubDate>Sun, 29 Jun 2008 15:16:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I don&#39;t think you really need WinMain to get a Windows GUI app. A regular main is ok.
</p></div></div><p>
If that were true there&#39;d be no need for Allegro&#39;s magic main mangling.<br />I remember we tried this a couple of years ago. As far as I recall, what you say is true for MinGW, but it is <i>not</i> true of MSVC. Unfortunately.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 29 Jun 2008 18:43:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://www.flipcode.com/archives/Win32_ConsoleWindowed_Tip.shtml">Here&#39;s</a> a way to get away with using main() with msvc.  Seems that if you link with &quot;/ENTRY:mainCRTStartup&quot;, it won&#39;t look for WinMain. I haven&#39;t tested it, though.</p><p>Here&#39;s an <a href="http://www.halcyon.com/~ast/dload/guicon.htm">article</a> about opening and using a console window from a GUI app.  Shows that you don&#39;t have to decide at link time if you want GUI or console.  It&#39;s just a bit more work to get some flexibility.</p><p>EDIT:<br />I had a second look at this.  It seems MinGW and DMC don&#39;t care about whether you use main or WinMain, but MSVC does.  It&#39;s easy to fix that, though.</p><p>All that&#39;s required is to add this in a header:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#if _MSC_VER</span>
   <span class="p">#pragma comment(linker,"/ENTRY:mainCRTStartup")</span>
<span class="p">#endif</span>
</pre></div></div><p>
Or to the command line, or in Visual Studio project options.</p><p>I&#39;ve attached exhello.c modified to test this stuff.</p><p>Docs:<br /><a href="http://msdn.microsoft.com/en-us/library/f9t8842e(VS.71).aspx">http://msdn.microsoft.com/en-us/library/f9t8842e(VS.71).aspx</a></p><p>Maybe dumping WinMain could be an option for allegro 5?  I know that there&#39;s some startup code being run from Allegro&#39;s main on OS X, but maybe that could be run by allegro_init or something.</p><p>Getting rid of the END_OF_MAIN macro sure wouldn&#39;t hurt.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Mon, 30 Jun 2008 03:12:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Getting rid of the END_OF_MAIN macro sure wouldn&#39;t hurt.
</p></div></div><p>
Exactly.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I had a second look at this. It seems MinGW and DMC don&#39;t care about whether you use main or WinMain, but MSVC does.
</p></div></div><p>
Right, that fits with what I know. Did you check the Intel or Borland compilers (and whatever else Allegro supports in Windows)?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
All that&#39;s required is to add this in a header:</p><p>#if _MSC_VER<br />   #pragma comment(linker,&quot;/ENTRY:mainCRTStartup&quot;)<br />#endif</p><p>Or to the command line, or in Visual Studio project options.
</p></div></div><p>
Yeach, pragma&#39;s. Well, it beats forcing people to use a particular linker option with Allegro, and it makes it easier to implement ALLEGRO_NO_MAGIC_MAIN.<br />Do you know whether this works in all versions of MSVC, or just recent ones?</p><p>One final request: could you put up a post with this information in de development forum, or the mailing list? Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 30 Jun 2008 13:21:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It works with msvc 6 and 9, and Intel&#39;s latest compiler.  I noticed that Intel uses the msvc linker, and choosing the entry point is done by the linker anyway.</p><p>I haven&#39;t got Borland, Watcom or djgpp installed.   Not sure what exactly Allegro 5 is supposed to support either.</p><p>I&#39;ll post about this on the mailing list later.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Mon, 30 Jun 2008 23:09:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It works with msvc 6 and 9, and Intel&#39;s latest compiler. I noticed that Intel uses the msvc linker, and choosing the entry point is done by the linker anyway.
</p></div></div><p>
Ok, great!</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I haven&#39;t got Borland, Watcom or djgpp installed.
</p></div></div><p>
I meant Borland for Windows, I thought Allegro worked with that, but I could remember incorrectly. Don&#39;t care about DOS (END_OF_MAIN() doesn&#39;t do anything in DOS anyway).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Not sure what exactly Allegro 5 is supposed to support either.
</p></div></div><p>
I think MSVC and MinGW are the obvious targets, but the more the better, of course.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;ll post about this on the mailing list later.
</p></div></div><p>
Great, thanks!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 01 Jul 2008 02:57:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That has been discussed more than necessary.</p><p>I am always astonished by the amount of answer that are already sitting somewhere on the forum...</p><p>And how people don&#39;t manage to use the <a href="http://www.allegro.cc/forums/search/?keywords=undefined+reference+to+WinMain%4016&amp;member_name=&amp;member_name_id=null+&amp;order=rel&amp;forum_all=1">SEARCH</a> button !</p><p>Well, that does not matter anyway because people generally just ignore my statements.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 02 Jul 2008 00:39:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well, that does not matter anyway because people generally just ignore my statements.
</p></div></div><p>Thats because you don&#39;t bother reading what you&#39;re replying too <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p><p>Most of that &quot;unecessary&quot; discussion was about how to get rid of END_OF_MAIN, and not the original OP&#39;s question. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 02 Jul 2008 00:42:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wouldn&#39;t mind if a moderator would split this topic in two, starting with my first post, and put the END_OF_MAIN discussion in the allegrodev forum.  Then again, I don&#39;t know if that&#39;s even possible.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 02 Jul 2008 02:10:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thomas, please do not say I did not read the topic, because I did .</p><p>OTOH, you did NOT read correctly. The OP had a problem with END_OF_MAIN because he did not wrote it correctly. Wait, what do I see all along these search pages ? END_OF_MAIN() !</p><p>Incredible, no ?</p><p>As it&#39;s not the first time you quote me and search what&#39;s wrong, I think you have something against me. Yeah, I am that way.</p><p>I gave an incomer a good information, it&#39;s that there are people that already had the same problem as him, it&#39;s commonly the case, and to continue the magic there is a search page and even some tags to add links in your post !</p><p>Now, to the quote part:
</p><div class="quote_container"><div class="title">Thomas said:</div><div class="quote"><p>

Thats because you don&#39;t bother reading what you&#39;re replying too <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div></div><p>
In our talk you are the only one to assume that statement. </p><div class="quote_container"><div class="title">Thomas said:</div><div class="quote"><p>

Most of that &quot;unecessary&quot; discussion was about how to get rid of END_OF_MAIN, and not the original OP&#39;s question. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div></div><p>
You DO noticed that my post was aimed to the OP, there is no way I was answering the troll that have (as usual) came after the few OT answers.</p><p>(To the OP: <a href="http://www.allegro.cc/mockup.html">read this</a> to make your post looking better)</p><p>PS: I just noticed that the <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /> smiley is in fact somewhat a smiling alien : : )
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 02 Jul 2008 03:32:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
OTOH, you did NOT read correctly. The OP had a problem with END_OF_MAIN because he did not wrote it correctly. Wait, what do I see all along these search pages ? END_OF_MAIN() !
</p></div></div><p>That was answered already. And the thread had moved on. Notice you can&#39;t specify that you are replying directly to the original post using the post form, you are in fact taking part of a linear discussion. One which can, and will change.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 02 Jul 2008 03:34:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can&#39;t admit that posting about using the search button just aim the new comer and not people who are used to allegro and the a.cc forum, can&#39;t you ?</p><p>I know that was already answered, and if you read correctly my post you will notice the fact that the word &#39;search&#39; is all upper case, because I wanted to put the accent on the &#39;search before ask&#39; thing, and not on the answer (which was as you said already answered). When I gave a link to a search page that was On Topic, I was giving a hint, so why give a half cut hint ?</p><div class="quote_container"><div class="title">Thomas said:</div><div class="quote"><p>

One which can, and will change.
</p></div></div><p>
My English knowledge is too weak to understand that statement.</p><p>Anyway, we are both keeping our position so the situation wont change until one move.</p><p>As I don&#39;t like it that way and don&#39;t want to have and endless talk about that silly subject, let&#39;s say that we are both right:</p><p>I should have told at the beginning of my post something like &quot;To the OP:&quot;, and you shouldn&#39;t have taken that post for you or another regular member who knows that the answer is generally already sitting in the forum.</p><p>It&#39;s a closed debate for me.</p><p>Regards, Gull.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 02 Jul 2008 11:55:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Then again, I don&#39;t know if that&#39;s even possible.
</p></div></div><p>
No.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Wait, what do I see all along these search pages ? END_OF_MAIN() !
</p></div></div><p>
Yes, and you see the same thing anywhere else, including the book that piece of code is from (well, I think that has END_OF_MAIN(); but never mind). So in fact the OP should have been able to spot it from looking at the source he got his code from. Since he obviously didn&#39;t, the most logical thing to do was to point out the error directly rather than say something along the lines of &quot;you make a typo, but I&#39;m not going to tell you where it is, look it up yourself you lazy noob.&quot;</p><p>Anyway, I&#39;d rather talk about getting rid of END_OF_MAIN().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 02 Jul 2008 13:37:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>

Yes, and you see the same thing anywhere else, including the book that piece of code is from (well, I think that has END_OF_MAIN(); but never mind). So in fact the OP should have been able to spot it from looking at the source he got his code from. Since he obviously didn&#39;t, the most logical thing to do was to point out the error directly rather than say something along the lines of &quot;you make a typo, but I&#39;m not going to tell you where it is, look it up yourself you lazy noob.&quot;
</p></div></div><p>
You could also add that no one explained him his compiler output, what would have made him find his error.<br />While we are at it, let&#39;s do it.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">|</span><span class="k3">|</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span> allgtest, Debug <span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">|</span>
C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c<span class="k3">|</span><span class="k3">|</span>In function `_mangled_main<span class="s">':    /* the bug sits in the main function */</span>
<span class="s">C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c|8|warning: implicit declaration of function `printf'</span> <span class="c">/*it means that printf is used before being declared. check that you have #include &lt;stdio.h&gt; at the very beginning of your code. */</span>
C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c<span class="k3">|</span><span class="n">13</span><span class="k3">|</span>warning: type defaults to `<span class="k1">int</span><span class="s">' in declaration of `END_OF_MAIN'</span> <span class="c">/* the compiler can't find END_OF_MAIN declaration, it default to int */</span>
C:\MinGW\share\CodeBlocks\myprograms\allgtest\main.c<span class="k3">|</span><span class="n">13</span><span class="k3">|</span>warning: data definition has no type <span class="k1">or</span> storage <span class="k1">class</span> <span class="c">/* Here is the part that should have taken all your attention ! The compiler is crying about the fact that it does not found any END_OF_MAIN declaration. It's common compiler error when you mispelled a variable / function */</span>
\mingw\lib\libmingw32.a<span class="k2">(</span>main.o<span class="k2">)</span><span class="k2">:</span>main.c:<span class="k2">(</span>.text<span class="k3">+</span><span class="n">0x106</span><span class="k2">)</span><span class="k3">|</span><span class="k3">|</span>undefined reference to `WinMain@<span class="n">16</span><span class="s">'| /* That one comes from the fact that there is no END_OF_MAIN() at the end of your main() function, and for the reasons given by other people in that post */</span>
<span class="s">||=== Build finished: 1 errors, 3 warnings ===| </span>
</pre></div></div><p>

</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Anyway, I&#39;d rather talk about getting rid of END_OF_MAIN().
</p></div></div><p>
That&#39;s a good point, but... I do not care writing END_OF_MAIN() at the end of all my projects. It&#39;s just 13 char... or a copy paste from another source ... Or perhaps it is just sitting in my simple skeleton for starting a project ? Well, it does not matter. If it disappear, then I will erase it from my projects.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 02 Jul 2008 14:46:25 +0000</pubDate>
	</item>
</rss>
