By Thomas Carriero
This tutorial assumes that you have already set up Code::Blocks and the MINGW
compiler in Windows. Now, we will add the SDL graphical libraries,
which will enable you to write graphical applications. After you’ve done
this, you can check out our tutorial on SDL (in progress).
I will assume you’ve installed Code::Blocks in C:Program FilesCodeBlocks. If you’ve installed it elsewhere, you will need to substitute the path you installed it instead of C:Program FilesCodeBlocks.
Step 1: Download SDL libraries
- Go here: http://www.libsdl.org/download-1.2.php
- Find the header entitled “Development Libraries”
- Under Win32, choose the option that says (Mingw32) after it. The current one at the time of writing this article is “SDL-devel-1.2.14-mingw32.tar.gz”, but there may be a newer version when you try. Click on this and download it to your desktop.
Step 2: Uncompress the downloaded .tar.gz file
If you do not have an application that can decompress this type of file, you can get one here: http://www.7-zip.org/download.html
You will want to uncompress it into its own folder, so that we can manually copy the files we need into the CodeBlocks folder.
Step 3: Copy the files from the uncompressed folder to your CodeBlocks folder
I suggest you start by opening both folders and putting them side by side, with the uncompressed folder on the left.
The left folder should look like this:
The right folder should look like this:
First, double click on the “include” folder in the left window (the uncompressed SDL folder). Move the SDL folder from the left window, into the “include” folder in the right window (the code blocks directory). When you finish doing this, your right window’s include folder should look like:
(It’s important that you copy the whole SDL folder, and not just the files inside of it.)
Now, go back to the view you had before you moved the SDL folder.
Go to the “bin” folder on the left. Move the SDL.dll file to the “C:Windows” folder. After you do that, the “C:Windows” folder should look somewhat similar to this:
Finally, you’ll need to copy the contents of the “lib” folder on the left folder over to the “lib” folder on the right. When you do this step, your right folder should look like this:
Test your installation
Your installation should be done at this point, so you can close the folders, and open up Code::Blocks.
Go to File and then New Project. Choose the SDL Application and hit Create. You will need to select a place to put it–I recommend you put it in its own folder. Open the main.cpp file and hit F9.
If you see compilation warnings, then you probably did not install the “include” folder correctly. If it compiles okay, but crashes complaining about SDL.dll, then you did not install the “bin” folder correctly.
Otherwise, you should see the following window pop up, which means that everything is working!
Popular pages
- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- How to make a game in 48 hours
- How to create a shared library on Linux with GCC – December 30, 2011
- Enum classes and nullptr in C++11 – November 27, 2011
- Learn about The Hash Table – November 20, 2011
- Rvalue References and Move Semantics in C++11 – November 13, 2011
- C and C++ for Java Programmers – November 5, 2011
- A Gentle Introduction to C++ IO Streams – October 10, 2011

Article source: http://feedproxy.google.com/~r/Cprogrammingcom/~3/xX6YWn8kf4I/
RSS Feed
Twitter
March 1st, 2012
diradiocast
Posted in
Tags: