SourceForge project page
Web Links

Your first program
1. Before you start

First, you should read Introduction, if you haven't done it before.

Next, you have to download latest version of SDL_Config before proceeding. You can do it in the Downloads section. After you do it, unzip downloaded file where you want, probably to directory like C:/SDL_Config.

After entering that directory, you will see following tree:

  • bin/

  • doc/

  • src/

  • tests/

As you probably suspect, bin stands for binary, and it's the directory where you will find builded library and executables of test programs along with their config files. Doc is the directory where API documentation (exactly the same as this API) can be found. Obviously, src contains library source code and project files, and automated test programs are kept insde tests. So far so easy, huh? :-)

2. Compiling library

SDL_Config, like many other open-source libraries, is distributed only with source code, without pre-built binaries. This approach was necessary, since SDL_Config can be tweaked in many ways (ie. changing operators), and I can't imagine distributing all possible versions. But don't worry, compilation of this library is trivial, as you will see in a moment.

Note: currently compilation process has been described only for DevCpp and Visual Studio, but I'm absolutely sure that it can be done without any problems also on other platforms (ie. Linux), in other enviroments, with other compilers.

For users of compilers other than DevCpp/MinGW or Visual Studio you should create library project in src/, add to it all .h and .c files you find in src/ (without SDL_config_auto_tests.h). For test projects that you will find in tests/, I would go with Console application, and link to SDL (ie. -lSDL -lSDLmain) and SDL_Config (-lSDL_Config or absolute path, see also paragraph 4). It may be also necessary to set other options, depending on your OS, IDE and compiler. It's pretty simple, but just don't try to do it if it's your second week of programming ;-)

2.0 Installing...

2.1 DevCpp + MinGW

Go to src/ directory and open file Now, compile it (click "Rebuild all"). Assuming that you have installed DevCpp correctly, SDL is also installed and it's in the include path (you might have to go to Tools->Compiler options->Directories to set it up), everything should compile fine, and SDL_Config.a should have been created in bin/.

2.2 Visual Studio

Go to src/ directory and open file Visual.sln. Now, compile it (click "Rebuild all"). Assuming that you have installed Visual Studio correctly, SDL is also installed and it's in the include path (Tools->Options->VC++ Directories), everything should compile fine, and SDL_Config.lib should have been created in bin/.

Ok, so now you have compiled library, let's compile some programs that will make use of it.

3. First test program

Go to tests/001 and open (DevCpp) or 001.sln (Visual Studio), depending on your compiler. Compile it. Most likely you will need to change ..\..\bin to your own SDL_Config library path (see paragraph 4). If everything went right, go to bin\ and run test_001.exe (DevCpp) or vc_test_001.exe (Visual Studio). Probably you will get error notification about missing SDL.dll file. That's ok, go to SDL downloads page and download runtime library (remember to match version with developement library!), in which you'll find SDL.dll - copy it to bin\, and run appropriate exe again. Stderr.txt file will be created. If you open it, there should be somewhere information that "all tests passed". In both compilers, if you use DLL version of SDL_Config and you want to distribute your programs, remember to attach SDL_Config.dll.

Well, congratulations, you have successfully installed SDL_Config and compiled it along with your first program. It wasn't so hard as you thought, ehh? ;-)

4. Writing your own programs

Say you want to create your own program that uses SDL_Config, and your platform is Windows + DevCpp. What steps should you take in order to compile it as smoothly as possible?

  1. Open, go to "Project Options", switch to tab "Build options" and in "Executable output directory" change ../bin to C:/DevCpp/lib (replace with path where your DevCpp lib directory is located). Then, change "Override output name" to libSDL_Config.a and check that C:/DevCpp/lib is in your C++ library search path (DevCpp -> Tools -> Compiler Options -> Directories -> Libraries). Alternatively, you could manually copy SDL_Config.a to mentioned DevCpp lib directory and change filename to libSDL_Config.a, but in the long run, doing it everytime you recompile SDL_Config, would be rather tedious. Well, the choice is yours :-)

  2. Copy SDL_Config.h to C:/DevCpp/include/SDL, and check that you have it in your C++ header search path (DevCpp -> Tools -> Compiler Options -> Directories -> C++ Includes). Alternatively, add C:/SDL_Config/src to your header search path.

  3. Link your program with following command line options: -lmingw32 -lSDL_Config -lSDLmain -lSDL (add here any other libraries you are using). Important note: from my and other people's experience, SDL_Config should be included as the first SDL library to link, and SDLmain should be linked before SDL, or you'll get undefined references.

Alternatively, if you don't want to do things described in steps 1 and 2, then (assuming your SDL_Config is located at C:/SDL_Config) you would use following command line: -lmingw32 C:/SDL_Config/bin/SDL_Config.a -lSDLmain -lSDL. No work to do at startup, but more typing with each project (and you can't distribute your projects easily, people will need to change this path to their own). Once again, the choice is yours :-)

Say you want to create your own program that uses SDL_Config, and your platform is Windows + Visual Studio. What steps should you take in order to compile it as smoothly as possible?

  1. Open Visual Studio, choose: File \ New \ Project...

  2. Select "Win32 Project", below type name and it's location

  3. Click "Application Settings", now what you select depends on what you want to do, but I would suggest to select "Empty project" and "Console Application"

  4. Create new / add existing source files and headers etc.

  5. Open project property pages, switch to C/C++ / Code Generation and change "Runtime Library" to Multi-threaded DLL (or its debug version). This step is needed by SDL.

  6. Switch to Linker / Command Line and type this: SDLmain.lib SDL.lib SDL_Config.lib

That's all, now you can compile.

Remember that if you will change "Debug" to "Release", you have to once again do steps 5 and 6.

Posted by Koshmaar on December 31 2005 16:03:578641 Reads - Print


Forgotten your password?
Request a new one here.
Banners Logo

Get Firefox!

Copyright © Hubert "Koshmaar" Rutkowski 2005