Author Topic: undefined reference to 'WinMain@16 error message  (Read 33945 times)

Offline jerryd

  • Single posting newcomer
  • *
  • Posts: 7
undefined reference to 'WinMain@16 error message
« on: December 09, 2016, 05:33:06 am »
Code:Blocks forum,

 Code:Blocks 16.01   SDL2-2.0.5    Windows 7    Mingw32

 I'm getting the error message "undefined reference to 'WinMain@16'
 I read about this in the net but couldn't resolve it?

 I can just click on "compile current file" the error is gone but if I "build" I get the error.
 Also I can comment out "#include <SDL.h> and it will "build" with no error.

Jerry D.
« Last Edit: December 09, 2016, 06:23:53 am by jerryd »



Offline jerryd

  • Single posting newcomer
  • *
  • Posts: 7
Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #3 on: December 09, 2016, 11:51:27 pm »
Code:Blocks forum,

 Here's the information I left out in my original post.

 I am running Code::Blocks version 16.01 on Windows 7 Professional SP1
 The compiler I use is Mingw32 and search directories set to
 C:\SDL2-2.0.5\include\SDL.  There are no relative paths in my setup.

 When I build a simple "Hello World" program there are no errors and
 it runs successfully.  If I add #include <SDH.h> and try to build it
 again I get the error message 'undefined reference to 'WinMain@16'
 
 File name is main.cpp

#include <SDL.h>
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}



 BUILD LOG WITHOUT #include <SDL.h>

-------------- Build: Debug in SDL (compiler: GNU GCC Compiler)---------------

 mingw32-g++.exe -Wall -std=c++11 -fexceptions -g -mwindows -std=c++11 -mwindows -IC:\SDL2-2.0.5\include\SDL2 -I"C:\Program Files\CodeBlocks\SDL" -IC:\SDL2-2.0.5\include\SDL2 -I"C:\Program Files\CodeBlocks\SDL" -c "C:\Program Files\CodeBlocks\SDL\main.cpp" -o obj\Debug\main.o
 mingw32-g++.exe -LC:\SDL2-2.0.5\lib -LC:\SDL2-2.0.5\lib -o bin\Debug\SDL.exe obj\Debug\main.o  -lmingw32 -lSDL2main -lSDL2 -lmingw32 -lSDL2main -lSDL2 
 Output file is bin\Debug\SDL.exe with size 1.01 MB
 Process terminated with status 0 (0 minute(s), 0 second(s))
 0 error(s), 0 warning(s) (0 minute(s), 0 second(s))


 
 BUILD LOG WITH #include <SDL.h>

-------------- Build: Debug in SDL (compiler: GNU GCC Compiler)---------------

 mingw32-g++.exe -Wall -std=c++11 -fexceptions -g -mwindows -std=c++11 -mwindows -IC:\SDL2-2.0.5\include\SDL2 -I"C:\Program Files\CodeBlocks\SDL" -IC:\SDL2-2.0.5\include\SDL2 -I"C:\Program Files\CodeBlocks\SDL" -c "C:\Program Files\CodeBlocks\SDL\main.cpp" -o obj\Debug\main.o
 mingw32-g++.exe -LC:\SDL2-2.0.5\lib -LC:\SDL2-2.0.5\lib -o bin\Debug\SDL.exe obj\Debug\main.o  -lmingw32 -lSDL2main -lSDL2 -lmingw32 -lSDL2main -lSDL2 
 C:/Program Files (x86)/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/4.9.2/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
 collect2.exe: error: ld returned 1 exit status
 Process terminated with status 1 (0 minute(s), 0 second(s))
 2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

 OTHER THINGS I HAVE TRIED

 There was a suggestions on the web regarding placing -mwindows as compiler
 flag which you can see in the Build logs.

 Select the checkbox  in Settings-> Compiler > Build options "Explicitly add currently compiling file's directory to compiler search dirs".

 Closing and reopening Code:Blocks.

 Go to project > build option and put a check mark on "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]".

 project --> build option Put check mark on " Have g++ follow the C++11 ISO C++ language standard [-std=c++11]"


 Any suggestions?

Jerry D.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #4 on: December 09, 2016, 11:55:44 pm »
PLEASE READ YOUR OTHER THREAD or I will ask for you to be banned!!

Follow this link if you are NOT a troll; if you are a troll get lost!


Edit: Sorry, at first reading it looked like you were a newbie, who failed to read the replies to your first post.
But, you are just a newbie who starts new threads for no reason, instead.

I suggest you fix the main function to match what is on the link below look up one FAQ.

http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22

What you should have
Code
int main(int argc, char *argv[])

Tim S.
« Last Edit: December 10, 2016, 12:10:19 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: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #5 on: December 10, 2016, 12:14:36 am »
Per offsite FAQ, "-mwindows" goes into the linker other/extra settings; it looks like you put it into the compiler other/extra settings.

Tim S.
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 jerryd

  • Single posting newcomer
  • *
  • Posts: 7
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #6 on: December 10, 2016, 01:01:47 am »
stahta01,

 I read both of BlueHazzard's suggested links.
 His first one suggested that I follow his format which is why I updated
 my post to his specs.


 His second suggested a link at:
 http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22     WHICH OFFERED THE SEVERAL SUGGESTIONS.

 ONE SUGGESTION WAS:
 "SDL can be built with Visual C++, Cygwin, MinGW, and Dev-C++".

 Code:Blocks isn't mentioned but there were many web sites showing
 how use SDL with Code:Blocks.
 I used Lazy Foo' tutorial at:
 http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php


 I'M NOT USING VISUAL C++ SO SOME THINGS DON'T APPLY.


 IN THE WINDOWS SECTION AT http://wiki.libsdl.org/Installation it said
 "optionally link SDLmain.lib if you want SDL to provide a WinMain()".
 I REMOVED THIS LINK BUT STILL GOT THE SAME ERROR MESSAGE.


 Is there some other way I should post this or is there something else
 I should post?

Jerry D.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #7 on: December 10, 2016, 01:06:48 am »
Per offsite FAQ, "-mwindows" goes into the linker other/extra settings; it looks like you put it into the compiler other/extra settings.

Tim S.

Edit: I have no idea if this flag is needed or not. I am guessing it will be needed later.
« Last Edit: December 10, 2016, 02:00:38 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: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #8 on: December 10, 2016, 01:30:28 am »
I suggest you use SDL2 Hello world code instead of the code that is C Hello world.

If you want a better site on using Code::Blocks and SDL2; I would suggest http://www.willusher.io/pages/sdl2/
But, most people do use the Lazy Foo's site; I really NOT sure what help I can give since you seem to NOT know what questions are valid for this site. Try to ask a valid CB Question; after reading the rules http://forums.codeblocks.org/index.php/topic,9996.0.html

NOTE: The real thing you need to learn is the information about your compiler!
Is it MinGW32 GCC or MinGW64 GCC?
Is it an 64 bit or 32 bit compiler?
What GCC version is it?

The most important is 64 or 32 bit compiler.

I will create a CB Project Template using the code from http://www.willusher.io/pages/sdl2/ and post it in this thread.
DO NOT START ANOTHER THREAD ON THE SAME TOPIC!
I will be using an 32 bit MinGW32 GCC compiler for my building of the CB Template project.

Tim S.
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: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #9 on: December 10, 2016, 01:50:02 am »
Added CB Template file.

Setting -> Global Varible
My Global Variable setting are this
Variable name: sdl2
Base: C:\SDL2-2.0.5\i686-w64-mingw32

In my case this means "$(#sdl2.include)" is replaced by CB with "C:\SDL2-2.0.5\i686-w64-mingw32\include".
$(#sdl2.lib) is replaced by CB with "C:\SDL2-2.0.5\i686-w64-mingw32\lib".
$(#sdl2.bin) is replaced by CB with "C:\SDL2-2.0.5\i686-w64-mingw32\bin".

Just unzipped the template file into a directory and set the global variable and post the build log.
Please try to use code tags that is the "#" button in the menu.

Tim S.
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: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #10 on: December 10, 2016, 01:52:38 am »
Example of posting code in code tags.
NOTICE: The main function is "int main(int, char**)" instead of "int main()" this makes a difference; but, my prior note of this was NOT understood by you. Edti2: If you do NOT fix that you will in time get. "undefined reference to `SDL_main'"

Edit: This is the simplest SDL2 code I know about it does nothing besides inits and quits SDL2.

Tim S.

Code
#include <iostream>
#include <SDL2/SDL.h>

int main(int, char**){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_Quit();
return 0;
}

Edit3: Added build and run logs.
Code
-------------- Build: Release in SDL2_Test (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -O2 -IC:\SDL2-2.0.5\i686-w64-mingw32\include -c C:\Devel\open_source_code\no_version_control\Test\SDL2_Test\main.cpp -o obj\Release\main.o
mingw32-g++.exe -LC:\SDL2-2.0.5\i686-w64-mingw32\lib -LC:\SDL2-2.0.5\i686-w64-mingw32\bin -o bin\Release\SDL2_Test.exe obj\Release\main.o  -lmingw32 -lSDL2main -lSDL2 -s 
Output file is bin\Release\SDL2_Test.exe with size 544.50 KB
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))

Code
-------------- Run: Release in SDL2_Test (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\Devel\open_source_code\no_version_control\Test\SDL2_Test\bin\Release\SDL2_Test.exe
Executing: "C:\Program Files\CodeBlocks/cb_console_runner.exe" "C:\Devel\open_source_code\no_version_control\Test\SDL2_Test\bin\Release\SDL2_Test.exe"  (in C:\Devel\open_source_code\no_version_control\Test\SDL2_Test\.)
Process terminated with status 0 (0 minute(s), 2 second(s))
« Last Edit: December 10, 2016, 01:58:24 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 jerryd

  • Single posting newcomer
  • *
  • Posts: 7
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #11 on: December 10, 2016, 02:57:59 am »
stahta01,

 Progress!!

 Following your suggestion I changed my SDL location to
 "C:\SDL2-2.0.5\i686-w64-mingw32\include" and updated all
 the compiler and build options.

 I no longer get the error message but when I try to run I get:

 "The application was unable to start correctly(0x00000007b)"

 I know this probably means a mismatch between 32 bit and 64 bit
 as you suggested.
 
 My system is Windows 7 Professional 64 bit.
 The SDL download was SDL2-2.0.5-win32-x64.zip
 The Code:Blocks download was from codeblocks-16.01mingw-setup.
 
 I'm new to this forum and Code:Blocks so I don't understand of
 what you mean by "Please try to use code tags that is the "#"
 button in the menu.

Jerry D.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Updated version of "undefined reference to 'WinMain@16 error message"
« Reply #12 on: December 10, 2016, 04:19:49 am »
My system is Windows 7 Professional 64 bit.
 The SDL download was SDL2-2.0.5-win32-x64.zip
 The Code:Blocks download was from codeblocks-16.01mingw-setup.

The codeblocks-16.01mingw-setup means you likely are using TDM's MinGW32 GCC which is 32 bit.
I downloaded SDL2-devel-2.0.5-mingw.tar.gz which contained both 32 bit and 64 bit files.

I tried the "SDL2-2.0.5-win32-x86.zip" first; but, it only had the 32 bit DLL which is NOT enough to build a SDL project from source code.

Edit: I am NOT good with images and to me I see no way to tell you where the # button is without posting an image.
Too tired to search for another poster who did the image in the past. Will try to test this tomorrow on my 64 bit Laptop;
not certain where the problem is.

The # button just adds this to your post [ code ][ /code ] without the spaces before and after the square brackets.

Tim S.
« Last Edit: December 10, 2016, 04:26:46 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 Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: undefined reference to 'WinMain@16 error message
« Reply #13 on: December 10, 2016, 10:14:41 am »
I merged the two threads.
Please do not start two threads if you update your own topic.

Offline jerryd

  • Single posting newcomer
  • *
  • Posts: 7
Re: undefined reference to 'WinMain@16 error message
« Reply #14 on: December 10, 2016, 06:25:09 pm »
stahta01,

 Got a late start on this problem today because I was up past 2AM.
 I found a 64 bit mingw32 that took a long time to download and
 then I had to figure how to set it up in Code:Blocks for compiling
 and Debugging.

 I Also had to update all the project's build options and properties.

 After all that was complete everything worked.  I went back and
 removed -mwindows from the project settings and it still worked.
 I see it still shows up in the Build Log so it may be in the
 makefile.

 Thanks much for your interest and all your suggestions.  I'm sure
 I'll be back with more questions as I get deeper into SDL code.

 FYI here's the latest Build log:
-------------- Build: Debug in SDL (compiler: Copy of GNU GCC Compiler(64))---------------

x86_64-w64-mingw32-g++.exe -Wall -fexceptions -std=c++11 -g -mwindows -std=c++11 -mwindows -IC:\SDL2-2.0.5.64\x86_64-w64-mingw32\include\SDL2 -IC:\SDL2-2.0.5.64\x86_64-w64-mingw32\include\SDL2 -I"C:\Program Files\CodeBlocks\SDL" -c "C:\Program Files\CodeBlocks\SDL\main.cpp" -o obj\Debug\main.o
x86_64-w64-mingw32-g++.exe -LC:\SDL2-2.0.5.64\x86_64-w64-mingw32\lib -LC:\SDL2-2.0.5\lib -o bin\Debug\SDL.exe obj\Debug\main.o  -lmingw32 -lSDL2main -lSDL2 
Output file is bin\Debug\SDL.exe with size 2.61 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 
Didn't see a way to mark this post as SOLVED.
 
Jerry D.