Skip to content

How to setup SDL2 with Code::Blocks on Windows

Amine B. Hassouna edited this page Sep 14, 2021 · 2 revisions

Install Code::Blocks

The easiest way to setup Code::Blocks is to use the setup executable with MinGW (C/C++ compiler).
Follow this tutorial: Installing Code::Blocks

Setup SDL2

  1. Download the development library from www.libsdl.org.

Download SDL2 dev lib

  1. Use WinRAR to extract the compressed file. Right-click on the downloaded file and click on Extract file....

SDL2 archive contextmenu

  1. In the "Destination path" text field, set C:\ as shown below, then click on OK.

Extract SDL2

  1. Go to the C:\ disk folder and verify that the SDL2 library was extracted successfully (as show below).

Verify SDL2

Your first SDL2 project

  1. Open Code::Blocks.
  2. Click on New button (has a paper with a plus sign as icon).
  3. Click on Project... as shown below.

  1. In the opened window, scroll down and select SDL2 project, then click on Go.

  1. The following window shows a welcome message, so it is better to tick the Skip this page next time, then click on Next.

  1. Now you should give a title to your project (It is a good practice to don't use spaces)
    Do not forget to select a folder to put your project in. Do that by clicking on the ... button.
    Then just click on Next.

  1. At this step, you should select the location of the SDL2 library.
    Click on ... button.

Go to the C:\<The library folder>\x86_64-w64-mingw32 as shown below.
In our case: C:\SDL2-2.0.16\x86_64-w64-mingw32

Then click on Next.

  1. Click on Finish to create your project.

  1. In the project tree (left panel), double-click on main.cpp to open it.

  1. Remove all the content of the default main.cpp file. (Use Ctrl + a to select all)
  2. Go to sdl2-pointerless and copy all the content to your main.cpp file. (Use Ctrl + a to select all)

  1. Finally, build and run your project.

Getting started with SDL2

Take a look on the SDL2 pointerless project.
It is one-file C SDL2 project. It is meant for beginners to let them create SDL-based projects without any pointer specific knowledge. It offers a micro-library that help create any grid-based user interface.
The only dependency of this project is the SDL2 library.

SDL2 examples, projects and tutorials

See SDL/SDL2 samples and projects

License

Author: Amine B. Hassouna @aminosbh

This tutorial is distributed under the terms of the MIT license