User forums > Using Code::Blocks
undefined reference to 'WinMain@16 error message
jerryd:
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.
BlueHazzard:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
BlueHazzard:
http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
jerryd:
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.
stahta01:
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.
--- Quote from: BlueHazzard on December 09, 2016, 03:53:37 pm ---http://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
--- End quote ---
What you should have
--- Code: ---int main(int argc, char *argv[])
--- End code ---
Tim S.
Navigation
[0] Message Index
[#] Next page
Go to full version