Setting up SDL_GPU with Code::Blocks [Solved]

Basic Problem:
I do not know how to setup the SDL_GPU external library with a Code::Blocks project on Windows 10. I already setup SDL 2.0 with Image, Mixer, and TTF external libraries using the Lazy Foo SDL2 tutorial (with mingw32 compiler). However, non of SDL_GPU’s releases have all the same files (including the Mingw32 release). I do not understand how to set the library up nor could I find resources to help with this particular setup. The SDL_GPU site says to use CMake(which I tried), but I do not understand what files it generates or how I’d use them. Any help on this particular problem or even with more general information on including libraries with C++ projects would be greatly appreciated. Thank you.

Extra Information:
The slightly older Mingw32 release of SDL_GPU had many header files, libSDL2_gpu.a, libSDL2_gpu.dll, and libSDL2_gpu.dll.a. Each file had a release and debug copy.
The SDL_Image library had bin folder with SDL2_image.dll and other dll’s, had an include folder with a single header file, and had a lib folder with libSDL2_image.a, libSDL2_image.dll,, and a pkgconfig folder with SDL2_image.pc.
The SDL_GPU site provides source files but I wouldn’t know how to properly create or implement a usable library myself. I tried to just put all source and header files into my project, but it had errors like not including Glew.h. I may have been able to brute force solve the compilation errors, but I figured using a library would be a far better solution.
Link to the SDL_GPU library

Note it is not a part of
Link to lazy foo tutorial
I have been working with SDL for about 1/2 a year on a 2D game engine.
My motivation for using this library is that is has automatic batching for draw commands to speed up rendering and have access to a shader API w/o having to use OpenGL.
This is my first forum post so I apologize if there’s something wrong with it.

Besides using CMake, setting up a project to use SDL_gpu is very similar to how you’d use SDL proper. The builds available for SDL_gpu are pretty old right now, so building from source is definitely recommended. I’ve been putting together some scripts for automated builds which would keep the builds up to date, but some pieces need work.

Have you tried using the GUI version of CMake? You can set that up to generate the build files for Code::Blocks and then run the project in the IDE and it produces the library files you need (.a, .dll.a, and .dll). If you need further help using that or the command-line version, just ask. The include files end up in ./include, the library files in ./lib, and the dll in ./bin for the most recent SDL_gpu. If you have a choice between release and debug builds, don’t sweat it and just choose one. “Release” is probably the way to go if you’re not expecting to dive into SDL_gpu’s code - the binary will be smaller and faster.

Once you have the headers and the lib files (.a for static linking, .dll.a and .dll for dynamic linking - dynamic is recommended), the rest is just as you did with SDL. Lazy Foo might not cover all the details of “why?”, but you need to tell the compiler where to find the header files (Project build options > Search directories > Compiler) and you need to tell the linker where to find the lib files (Project build options > Search directories > Linker). Then you need to specify which libraries will be linked in Project build options > Linker settings. Lazy Foo adds each item explicitly with a “-l” flag, so you can add “-lSDL2_gpu” the same way. Order sometimes matters, so put this one before “-lSDL2”.

The .dll should exist alongside your project’s binary, wherever that is. I think Code::Blocks will also look in the project file’s directory for DLLs if you Run it in the IDE. I don’t recommend putting it in the System folder, as then you can run into versioning issues between different projects and it hides errors in the case that you forget to package the DLL with your program for distribution.

Also, the only header file you need for normal usage is SDL_gpu.h. The rest are for advanced usage, either mixing SDL_gpu with calls to a specific version of OpenGL or using your own custom renderer to replace the built-in ones.

Okay, I didn’t realize CMake generates project files as it didn’t until I modified CMAKE_CODEBLOCKS_EXCECUTABLE to correct path in CMake GUI.

For CMake, I used the src folder of sdl-gpu-master as the source, and current generator was Codeblocks MinGW Makefiles, and then generated. After changing the above variable, the output folder had the project, a makefile, a lib folder that has an include folder that has all the header files (lib / include / headerfiles, is that correct?), and a bunch of other cmake stuff.

I opened the project in Codeblocks and built it (later tried running it), but I did not find any new files generated except project layout. In project build options it says “this is a custom make file” which is checked and name is Makefile.

How do I get Codeblocks to generate the library files?
Thank you.

Extra Information:

This tutorial (for Linux) said to set build target to install, but I don’t see that option anywhere.
This page said to change one of the lines of ‘Make Commands’ so $target becomes the output file name with .exe, I don’t know what the output file is and trying it with project.exe didn’t seem to have any effect.

Also, could I ask what the difference is between libSDL2_image.dll vs. SDL2_image.dll and what the SDL2_image.pc file is (using sdl_image as an example)? Do these files matter?

Still can’t get this to work. Codeblocks output when I try to run CMake created project…

Checking if target is up-to-date: mingw32-make.exe -q -f Makefile all
Running command: C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f “D:/SDL2-2.0.5/cMakeTest2/Makefile” VERBOSE=1 all
"C:\Program Files\CMake\bin\cmake.exe" -HD:\SDL2-2.0.5\sdl-gpu-master\src -BD:\SDL2-2.0.5\cMakeTest2 --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start D:\SDL2-2.0.5\cMakeTest2\CMakeFiles D:\SDL2-2.0.5\cMakeTest2\CMakeFiles\progress.marks
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'D:/SDL2-2.0.5/cMakeTest2’
mingw32-make.exe[1]: Nothing to be done for ‘all’.
mingw32-make.exe[1]: Leaving directory ‘D:/SDL2-2.0.5/cMakeTest2’
“C:\Program Files\CMake\bin\cmake.exe” -E cmake_progress_start D:\SDL2-2.0.5\cMakeTest2\CMakeFiles 0

Then I tried to run this command in command prompt
C:/PROGRA~2/CODEBL~1/MinGW/bin/mingw32-make.exe -f “D:/SDL2-2.0.5/cMakeTest3/Makefile” all

(source is this link:

This is what command prompt said (this came after a warning about a minimum version line for CMake)

– Configuring done
– Generating done
– Build files have been written to: D:/SDL2-2.0.5/cMakeTest2
mingw32-make.exe[1]: CMakeFiles\Makefile2: No such file or directory
mingw32-make.exe[1]: *** No rule to make target ‘CMakeFiles\Makefile2’. Stop.
mingw32-make.exe: *** [all] Error 2

(Note that Makefile2 does exist in CMakeFiles folder).
Any help would be greatly appreciated.

forgot that between the last 2 lines of the command prompt output there’s this line…

D:/SDL2-2.0.5/cMakeTest2/Makefile:82: recipe for target ‘all’ failed

I figured it out :smile: . After using CMake to make tinyxml2 into a usable library, I realized that the line “where is the source code” of CMake GUI was asking for sdl-gpu-master. I was always putting in sdl-gpu-master/src because that’s where the C++ source files were. From there I filled in necessary blanks and didn’t modify any of the check-boxes. Then I ran the resulting project once CMake stopped complaining and had the files which I included into my project properly.