Compiling on Linux
Index
Contents
Compiling SDL
Extract SDL, run configure and then make:
tar zxvf SDL-1.2.7.tar.gz cd SDL-1.2.7 ./configure make make install
You may also change how SDL gets compiled by adding options to ./configure. To display what options you can change type in:
./configure --help
Test your install by typing in:
sdl-config --version
Another way to test how SDL works is to try the test applications:
cd test ./configure make make install ./testalpha ./testbitmap # etc ..
Compiling an SDL application using GCC
Example 1
- Here is a sample makefile for gcc. It compiles sdltest.c file into a binary called sdltest.
all:
gcc `sdl-config --cflags` `sdl-config --libs` -osdltest sdltestExample 2
- This makefile compiles two .c files into a binary called sdltest.
all:
gcc -c `sdl-config --cflags` sdltest1.c sdltest1.o
gcc -c `sdl-config --cflags` sdltest2.c sdltest2.o
gcc `sdl-config --libs` sdltest1.o sdltest2.o -osdltestNote: Makefiles should use tabs instead of spaces unlike here.
If you are using an extra library and find yourself getting compilation errors related to functions not being found you may need to add this to the flags in addition to the ones created by sdl-config. For instance, if you are using SDL_image then add -lSDL_image to the compile command.
I installed SDL from source but can't build or run SDL applications
Edit the file /etc/ld.so.conf, and make sure it contains the line:
/usr/local/lib
As root, run /sbin/ldconfig
Make sure /usr/local/bin is in your execution path:
export PATH=$PATH:/usr/local/bin/
Make sure that there aren't any other versions of SDL on your system, and that you have removed any file named "config.cache" from the directory of the software that refuses to build.
If all of the above still don't work, send e-mail to the SDL mailing list with the output from the following commands run from the directory of the software that refuses to build:
- which sdl-config
- sdl-config --version
- locate libSDL
- tail config.log
