News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

SDL and Codeblocks/MinGW - WinMain undefined reference

Started by aboeing, June 16, 2009, 05:38:33 AM

Previous topic - Next topic

aboeing

Hi,

I am trying to compile a sample SDL program, and I keep getting a:
undefined reference to `_WinMain@16'
problem.

I am using the SDL 1.2.13 mingw build from http://www.libsdl.org/download-1.2.php
SDL-devel-1.2.13-mingw32.tar.gz (Mingw32)

And a SDL sample program from here:
http://friedspace.com/SDLTest.c

This is the command line the compiler is using:
mingw32-g++.exe -LC:\lib\SDL-1.2.13\lib  -o "bin\Debug\sdl test.exe" obj\Debug\main.o    C:\lib\SDL-1.2.13\lib\libSDL.dll.a C:\lib\SDL-1.2.13\lib\libSDLmain.a

This is the output:
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings

I have set the project to 'console' and set the include directory for SDL and added libSDL.dll.a and libSDLmain.a libraries.

Does anyone know how to solve the undefined reference problem?

Jenna


aboeing

Yes, I did a search and saw that topic. I've tried adding '-lmingw32 -lSDLmain -lSDL -mwindows' to the compiler options, but that did not help.

MortenMacFly

Quote from: aboeing on June 16, 2009, 08:08:14 AM
Yes, I did a search and saw that topic. I've tried adding '-lmingw32 -lSDLmain -lSDL -mwindows' to the compiler options
This is not a compiler, but a linker option. Please post the full build log to see if that helps... probably a sample project would be best.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

aboeing

This is the full build log:

mingw32-g++.exe -LC:\lib\SDL-1.2.13\lib  -o "bin\Debug\sdl test.exe" obj\Debug\main.o    C:\lib\SDL-1.2.13\lib\libSDL.dll.a C:\lib\SDL-1.2.13\lib\libSDLmain.a
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings

I can't attach the codeblocks project, it says the board is full.

aboeing


MortenMacFly

Quote from: aboeing on June 17, 2009, 03:40:24 AM
I have uploaded the codeblocks project with source here:
http://www.adrianboeing.com/tmp/sdl%20test.zip
Link against "mingw32" first. Next time you can try to use the wizard to create a project template for you. Cause that's what I have done and it just worked. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

aboeing

Thanks MortenMacFly! That was it, I had the dependencies in the wrong order:

for future reference this is the order you must have:
-lmingw32
-lSDLmain
-lSDL