Author Topic: undefined reference to 'WinMain@16  (Read 66021 times)

chrisvj

  • Guest
undefined reference to 'WinMain@16
« on: June 05, 2011, 03:22:47 am »
When attempting to run a file, I get the following:
Code
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16|
||=== Build finished: 1 errors, 0 warnings ===|

this is the build log:
Code

-------------- Build: Debug in delta3d ---------------

mingw32-g++.exe -L..\..\..\..\..\Delta3D\REL-2.5.0\inc -LC:\Delta3D\REL-2.5.0\inc  -o bin\Debug\delta3d.exe obj\Debug\main.o    -lgdi32 -luser32 -lkernel32
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16
'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
Will someone please tell me what I'm doing wrong? Ty in advance

EDIT: This happens even with a blank file
« Last Edit: June 05, 2011, 03:30:57 am by chrisvj »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7592
    • My Best Post
Re: undefined reference to 'WinMain@16
« Reply #1 on: June 05, 2011, 04:02:32 am »
This a compiler question NOT a Code::Blocks Question. In the future ask compiler questions on a site that supports the Compiler.
Turning on Full Compiler Logging will help that site to help you.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

IIRC, you are missing the -mwindows option.
http://mingw-starter.blogspot.com/2008/02/mingw-sdl.html

Tim S.
« Last Edit: June 05, 2011, 04:04:56 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7592
    • My Best Post
Re: undefined reference to 'WinMain@16
« Reply #2 on: June 05, 2011, 09:58:56 am »
You NEED to learn the difference between an Compiler and the IDE!!!!!!!!!
DO NOT PM ME!!!!!!!

You need to learn to search this site and the internet!

http://forums.codeblocks.org/index.php/topic,7906.0.html

Tim S.
« Last Edit: June 05, 2011, 10:23:18 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline xunxun

  • Almost regular
  • **
  • Posts: 187
Re: undefined reference to 'WinMain@16
« Reply #3 on: June 05, 2011, 10:27:10 am »
You should create a GUI project, but you created a console program.
Regards,
xunxun

Offline colnelb

  • Single posting newcomer
  • *
  • Posts: 2
Re: undefined reference to 'WinMain@16
« Reply #4 on: December 19, 2012, 01:32:39 am »
I downloaded the latest version of Code::Blocks and installed the compiler that came with the download, MinGW.  I am having the same problem. "undefined reference to 'WinMain@16'.  I went to the MinGW blog site and found a reference to requiring to turn on the "mwindows flag".  I have attempted and was unable to find a "compiler flag" "mwindows" anywhere in the compiler settings provided through the installed Code::Blocks IDE.

 I did find a readme file in the MinGW folder installed under Code::Blocks that had the following comment: "This edition of TDM-GCC is an unofficial replacement for the official GCC binaries distributed by the MinGW project; please note the following caveats:  * TDM-GCC is not formally affiliated with or endorsed by the MinGW project.   * No level of support for TDM-GCC is in any way guaranteed, although a best effort is made to fix bugs as they are found or forward them to GCC Bugzilla."

At this point I am at a loss.  Since Code::Blocks provided an "unofficial" version of MinGW with the installation of the IDE, then it is somewhat an issue of the Code::Blocks IDE, not just a "compiler problem".

How do I fix this problem?  Do I download the MinGW installer from SourceForge and attempt to install it under the Code::Blocks install?  How do I re-integrate the newer install of MinGW compiler with the existing installation of Code::Blocks? 

Let me add this comment: I am something of an experienced programmer from many years ago, attempting to re-learn C++ for a specific project that I want to do.  The level of difficulty I am in finding a solution to this issue would likely be more than anyone starting out would overcome.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7592
    • My Best Post
Re: undefined reference to 'WinMain@16
« Reply #5 on: December 19, 2012, 01:52:04 am »
I downloaded the latest version of Code::Blocks and installed the compiler that came with the download, MinGW.  I am having the same problem. "undefined reference to 'WinMain@16'.  I went to the MinGW blog site and found a reference to requiring to turn on the "mwindows flag".  I have attempted and was unable to find a "compiler flag" "mwindows" anywhere in the compiler settings provided through the installed Code::Blocks IDE.

Edit: "latest version of Code::Blocks" means nothing to me; post the version number!!

If you are trying to create a GUI program read this link.

http://forums.codeblocks.org/index.php/topic,7906.0.html
(Edit2: Look at the other linker option in the Image)
(Edit3: Project -> "Build Options" Tab: Linker Settings)

If you are NOT trying to create a GUI program; what are you trying to do?

Tim S.

« Last Edit: December 19, 2012, 01:57:28 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline colnelb

  • Single posting newcomer
  • *
  • Posts: 2
Re: undefined reference to 'WinMain@16
« Reply #6 on: December 20, 2012, 10:00:48 pm »
I found something interesting.  There is a problem with Code::Blocks in that it does not verify that the project/workspace folders/files are not read only before it calls the compiler and attempts to compile the project code.  I spend days "going down the rabbit hole" researching the spurious error message seen in the subject line before I found that the restored project/workspace folder from a prior project had been restored as "read only".  When the permissions were fixed, the project compiled without error.  Check the permissions on your project/workspace folders and files.