I have recently installed code::blocks on my system running windows 7 home premium 64-bit, and wanted to start learning SDL. The code::blocks executable is the one installed by the "codeblocks-12.11mingw-setup.exe"- setup wizard, which also installs gcc and MinGW as implied by the name. I proceeded to download the precompiled version of SDL 2.0 development files "SDL2-devel-2.0.0-mingw.tar.gz" from the SDL site, created a new empty project, pointed the compiler to the /include directory and the linker to the /lib directory of the 32-bit version of SDL 2.0 using the project specific search directories and set the IDE to treat the project as a GUI application instead of a console application. However, trying to build the project always results to a build error of the form:

undefined reference to `SDL_Init'
undefined reference to `SDL_Quit'
undefined reference to `WinMain@16'
=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===

Which is understandable since I have not specified any linker flags, but adding the flags -lmingw32 -lSDLmain -lSDL to "other linker options" in the IDE results in the error:

ld.exe  cannot find -lSDLmain
ld.exe  cannot find -lSDL
=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===

Implying it did indeed recognize the flag -lmingw32. I tried to copy the appropriate SDL dev files directly to MinGW/include and MinGW/lib, and placed the runtime DLL in the project directory to no avail. Do I have the wrong linker options for SDL 2.0, are they in the wrong order, or am I missing something else?

EDIT: checking all the involved files revealed that libSDLmain.a has been replaced by libSDL2main.a etc. in SDL 2.0. After replacing the linker options with -lmingw32 -lSDL2main -lSDL2 the linker stopped complaining about not finding missing statically linked libraries. However it now again fails to find the definition of the various SDL routines called in the program, giving the same output as stated in the first case (undefined reference to X).

EDIT2: Just found out i'm not alone with this problem, there is an old, unanswered question about the exact same problem on stackoverflow: https://stackoverflow.com/questions/17011028/i-can-compile-with-sdl1-2-but-not-with-sdl2-cb

Source code:

#include <SDL2/SDL.h>

int main(int argc, char* argv[])
  return 0;

Build log from building the project after adding the aforementioned linker options and SDL files directly in MinGW's /include and /lib directiories and removing the search directories from the project's options:

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

mingw32-g++.exe  -o bin\Debug\newProject.exe obj\Debug\newProject\newProject\main.o   -lmingw32 -lSDLmain -lSDL   -mwindows
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: cannot find -lSDLmain
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: cannot find -lSDL
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings (0 minutes, 0 seconds)
  • \$\begingroup\$ offtopic: Should I have asked this question at stack overflow instead of flooding the smaller gamedev community, as the issue is not specific to game development? \$\endgroup\$
    – jms
    Commented Jul 11, 2013 at 8:49
  • \$\begingroup\$ Well, not flooding, but yes, this is a question that's better suited for stackoverflow. \$\endgroup\$
    – House
    Commented Aug 30, 2013 at 3:47

2 Answers 2


After exhaustively troubleshooting everything, I finally noticed that I had accidentally linked the program to the 64-bit version of SDL while compiling for 32-bit, and now the project compiles and links effortlessly.

  • \$\begingroup\$ May I ask you to write down your command line here? \$\endgroup\$ Commented Aug 7, 2013 at 15:51

The correct flags for SDL 2.0.0 are -lSDL2main and -lSDL2


Not the answer you're looking for? Browse other questions tagged .