go here
https://www.codeblocks.org/downloads/binaries/
download
codeblocks-20.03mingw-setup.exe
from
Sourceforge.net
download should happen automatically
install codeblocks
then go here
and download
SDL2-devel-2.24.0-mingw.zip
unzip and copy this folder
x86_64-w64-mingw32
over to C:\SDL2 or maybe C:\development or whatever
then open codeblocks, Create a New Project, SDL2 project
a wizard comes up – give your project a name and location
it will ask you where SDL2 is
enter the path where you saved the SDL folder
C:\SDL2\x86_64-w64-mingw32
codeblocks will create a basic demo sdl2 project for you
you can view the C file in the codeblocks editor under the Sources folder
however, the code is a little bit wrong
change
#include <SDL.h>
to
#include <SDL2/SDL.h>
then save the file
and for this one example project there is an extra step that is needed
from codeblocks menu choose Settings / Global variables …
then press the New button
enter sdl2
and press OK
then in the base box enter the path where you saved the SDL folder
C:\SDL2\x86_64-w64-mingw32
then Close
you are only doing that because this demo project copies the sdl2 dlls over to the Debug and Build folders when you build the project
you can see this by going to the codeblocks menu and
choosing Project / Build Options / (change from Debug to project name)
and look for the tab named
Pre/post build steps
and in the Post-build steps you’ll see this line
XCOPY $(#sdl2)\bin*.dll $(TARGET_OUTPUT_DIR) /D /Y
so AFTER the exe is successfully built the final step of the build process will be to copy the dlls
that’s why you had to set the global variable
if you want to see the linker settings
then change to the tab named
Linker settings
also look at the tab named
Search directories
and under that loo at the sub tabs
Compiler
and
Linker
now from the menu choose Build / Build and run
a console window will open (where you will see the output of any printf and SDL_Log statements)
and another window will open that will be the executable you just built
when you close the executable you’ll see
exit code 0
in the console window
but in codeblocks you’ll see some weird exit code –
that is not the exit code of your executable, it is the exit code of the codeblock process that is running your executable
the console window only shows up when you run the program inside codeblocks
it doesn’t show up when you go to the debug or release folder and run the exe directly
you may have to go to your codeblocks install folder and copy
libgcc_s_seh-1.dll
libstdc+±6.dll
libwinpthread-1.dll
over to the debug and release folder