Setting up SDL with Eclipse CDT
I have included this guide as this is the setup I will be using for all my game-related tutorials and it will make them easier to follow if you are using the same environment. If you already have a satisfactory IDE/Compiler setup then you probably won't find anything useful here.
What is SDL?
SDL stands for Simple Directmedia Layer and is a cross platform library to access your computer's graphics, sound and input capabilities. In many ways it's like an open-source version of Microsoft's DirectX
What is the Eclipse CDT?
Eclipse is an IDE, originally made for writing Java applications, but with the C Development Toolkit it can be used to write C and C++ programs. Recently a standalone version of Eclipse specifically has been released and is available from the Eclipse download area. Eclipse is a development environment, not a compiler, so if you are using Windows you will need to install MinGW, a windows port of the GCC suite
Installing Eclipse
Once you have downloaded Eclipse, all you need to do is unpack it into a sensible directory and then run the application. You will need a JRE installed in order for Eclipse to run. If you are using Linux it should find all your compilers and tools; if you are using Windows is should find MinGW as long as it is installed
Installing SDL
This step differs depending on your operating system
- On Linux, Unix and variants, you will need to install libsdl-dev package for whatever distribution you are using
- On Windows, you will need to extract the development package from www.libsdl.org into your MinGW folder, so that the files from 'bin' in the archive go to MinGW/bin and so on.
Setting up your Eclipse project for SDL
Once you have created a new project using the Eclipse new project dialog (either C or C++), you will to add SDL support to the project. In the SDL documentation, you will see reference to an 'sdl-config' script. Unfortunately the limited shell capabilities of Windows mean that we have to put this info in manually. Open up the Project->Properties menu and you will see something like this:
Go into the C/C++ Build -> Settings page
- In the Compiler->Preprocessor section, add the defined symbol "main=SDL_main"
- In the Linker->Libraries section, add the libraries "mingw32" (Windows only), "SDLmain" and "SDL" libraries (in that order).
- In the Linker->Miscellaneous section, add "-mwindows" to the Linker Flags box (Windows only)
Now you can test it with this simple application
#include <SDL/SDL.h>
int main(int argc, char **argv) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Quit();
}
With any luck, you should be able to compile and run this without errors (although it won't do anything when you run it)
If you want SDL to do anything useful, you'd better read the next tutorial: SDL: The basics