Help Setting Up SDL Properly for a Windows IDE

My Question: I have installed CodeBlocks, Eclipse, and Dev-C++ (all 32-bit) on a Windows XP 32-bit machine (slow I know but it’s what I could get), but I cannot get them to work with SDL2 (32-bit developer download) by following various tutorials found here, lazyfoo, stack exchange, and on various IDE forums. I would like to ask if anyone can give me a link to a solid setup tutorial or provide me with instructions on how to install on any of these or another option.

Some Background: I was able to set SDL2 up fine on my Linux machine, but my system with Ubuntu 16.04 is too slow to properly render the graphics, so I’m forced to switch platforms. Also, I’m new to programming (esp with IDE) coming from a text editor and terminal compilation background, so I apologize if I miss some basic concepts.

Eclipse Problem: I cannot seem to build anything and when I attempt to run I receive a “Launch failed. Binary not found.” message. Any configuration attempts I make don’t seem to change this.

CodeBlocks Problem: When I attempt to build my code, it simply replies “error: 1d returned 1 exit status”, which I read is a problem with the linker, but I’m not sure what I did wrong because I am linking the SDL lib folder and using “-lmingw32 -lSDL2main -lSDL2” like many tutorials have suggested.

Dev-C++ Problem: The error says it can’t find the SDL.h file here, even after adding includes, library, etc.

I use Code::Blocks when I’m not testing out CLion, and I run on both windows and Linux platforms. Without the actual error messages, it’s hard to tell what problem you’re having. From experience though, Error: ld returned 1 exit status usually means that you didn’t link to the library for SDL, you’re missing a dependency link, or you have a the wrong bit depth, (ie you’re trying to compile as a 32 bit library, but you have the 64 bit library).

Never used Eclipse, can’t help you there.

Dev-C++, I at least hope you’re using the newer fork of the old Dev-C++ program. I used to use that until I found Code::Blocks. Post the full error message, please.

Error for CodeBlocks:

collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Error for Dev-C++

Compiling project changes…

  • Project Filename: C:\Code\Project1.dev
  • Compiler Name: TDM-GCC 4.9.2 32-bit Release

Building makefile…

  • Filename: C:\Code\Makefile.win

Processing makefile…

  • Makefile Processor: C:\Program Files\Dev-Cpp\MinGW64\bin\mingw32-make.exe
  • Command: mingw32-make.exe -f “C:\Code\Makefile.win” all

g++.exe -c main.cpp -o main.o -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -I"C:/code/SDL2-2.0.8/include" -m32
g++.exe -c main.cpp -o main.o -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -I"C:/code/SDL2-2.0.8/include" -m32

g++.exe main.o -o Project1.exe -L"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc -std=c++11 -L"C:/code/SDL2-2.0.8/lib/x86" -m32

main.o:main.cpp:(.text+0x1c): undefined reference to SDL_Init' main.o:main.cpp:(.text+0x28): undefined reference toSDL_GetError’
main.o:main.cpp:(.text+0x71): undefined reference to SDL_CreateWindow' main.o:main.cpp:(.text+0x7f): undefined reference toSDL_GetError’
main.o:main.cpp:(.text+0x9c): undefined reference to SDL_GetWindowSurface' main.o:main.cpp:(.text+0xc5): undefined reference toSDL_MapRGB’
main.o:main.cpp:(.text+0xdc): undefined reference to SDL_FillRect' main.o:main.cpp:(.text+0xe7): undefined reference toSDL_UpdateWindowSurface’
main.o:main.cpp:(.text+0xf3): undefined reference to SDL_Delay' main.o:main.cpp:(.text+0xfe): undefined reference toSDL_DestroyWindow’
main.o:main.cpp:(.text+0x103): undefined reference to SDL_Quit' C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32/libmingw32.a(lib32_libmingw32_a-crt0_c.o): In functionmain’:
C:/crossdev/src/mingw-w64-v3-git/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain@16’
collect2.exe: error: ld returned 1 exit status

C:\Code\Makefile.win:25: recipe for target ‘Project1.exe’ failed
mingw32-make.exe: *** [Project1.exe] Error 1

If there is another area I can post errors from, please let me know. Thank you.

For Code::Blocks, there’s another tab at the bottom, should be either Build Messages or Build Log that should have the rest of the error messages. Seems like a linking issue from my experiences in the past with that. Possibly the library not being the right depth.

Dev-C++, you included the header files, but didn’t link to the libraries from what I can tell. Or it’s the wrong bit depth again.

I’m guessing you’re using the 32 bit versions instead of the 64 bit versions of the other way around
http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/index.php

Problem solved: I was using the Visual C++ SDL2 download instead of the mingw download. Changing that one thing fixed all of my problems. Thank you everyone for all of the help.

Here is the Build Log error for Code::Blocks:

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

mingw32-g++.exe -LC:\code\SDL2-2.0.8\lib\x86 -o bin\Debug\sample.exe obj\Debug\01_hello_SDL.o -lmingw32 -lSDL2main -lSDL2
C:\code\SDL2-2.0.8\lib\x86/SDL2main.lib(Win32/Release/SDL_windows_main.obj):(.text[_main]+0x0): multiple definition of `main’
C:/Program Files/CodeBlocks/MinGW/bin/…/lib/gcc/mingw32/5.1.0/…/…/…/libmingw32.a(main.o):main.c:(.text.startup+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 4 second(s))
1 error(s), 0 warning(s) (0 minute(s), 4 second(s))

I was able to get Dev-C++ up and running by reinstalling it and downloading the mingw compiler separately. I’m not sure why this worked, but it did.

For Code::Blocks, I think SDL2main has to be linked after SDL2, or that you need to use this instead: int main(int argc, char** argv). Haven’t seen that one specifically, so just guessing at this point. I really hate linking in general.

With Dev-C++, that’s probably because the IDEs are overwriting each others PATH settings. Didn’t think of it before, but having more than one IDE installed at a time can cause issues, especially if they use the same type of compiler, (ie, mingw, or clang).

@game_designer, I empathise with your problem, I’ve recently moved from plain text editing to Code::Blocks, and had plenty of issue getting up and running. The compilation process was confusing to adapt to, having been doing everything via the command-line previously.

I’m not sure, but I think your issue with Code::Blocks stems from trying to link with Visual Studio libraries still.

Looking over your build log, the -LC:\code\SDL2-2.0.8\lib\x86 filepath isn’t what I’d expect from the mingw development libraries. Checking the Visual Studio development library download however, shows the same directory structure.

The Visual Studio SDL library, SDL2main.lib, and libmingw32.a both define ‘main’. Presumably, the mingw SDL library SDL2main.a does not.

Contrarily, I’ve found that SDL2main needs to be linked before SDL2. I’ve also had no issue with using int main(int argc, char *argv[]) in any of my code.

@Blerg I never thought about the IDEs overwriting each other’s paths. I’ll have to keep that in mind for future projects and eliminate all but one. Since I got both Code::Blocks and Dev-C++ working now, I’ll choose between those and ditch one and Eclipse.

@JessJ Thanks for letting me know about the linking order. I’ll also make sure to update my main function, as now I simply have int main() {return 0;} as the structure.