Author Topic: SDL and Codeblocks/MinGW - WinMain undefined reference  (Read 21633 times)

Offline aboeing

  • Single posting newcomer
  • *
  • Posts: 5
SDL and Codeblocks/MinGW - WinMain undefined reference
« on: June 16, 2009, 05:38:33 am »
Hi,

I am trying to compile a sample SDL program, and I keep getting a:
undefined reference to `[email protected]'
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 `[email protected]'
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?


Offline aboeing

  • Single posting newcomer
  • *
  • Posts: 5
Re: SDL and Codeblocks/MinGW - WinMain undefined reference
« Reply #2 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, but that did not help.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: SDL and Codeblocks/MinGW - WinMain undefined reference
« Reply #3 on: June 16, 2009, 08:17:05 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: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline aboeing

  • Single posting newcomer
  • *
  • Posts: 5
Re: SDL and Codeblocks/MinGW - WinMain undefined reference
« Reply #4 on: June 17, 2009, 03:34:39 am »
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 `[email protected]'
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.

Offline aboeing

  • Single posting newcomer
  • *
  • Posts: 5
Re: SDL and Codeblocks/MinGW - WinMain undefined reference
« Reply #5 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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: SDL and Codeblocks/MinGW - WinMain undefined reference
« Reply #6 on: June 17, 2009, 11:37:54 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: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline aboeing

  • Single posting newcomer
  • *
  • Posts: 5
Re: SDL and Codeblocks/MinGW - WinMain undefined reference
« Reply #7 on: June 19, 2009, 04:29:26 am »
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