How to Cross Compile Simple DirectMedia Layer a Step by Step Guide
Introduction
This tutorial will show how to cross compile the Simple DirectMedia Layer library on an GNU Linux embedded platform.
Overview of the project
Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games, including the award winning Linux port of "Civilization: Call To Power."
SDL supports Linux, Windows, Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX. The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS, and OS/2, but these are not officially supported.
SDL is written in C, but works with C++ natively, and has bindings to several other languages, including Ada, C#, D, Eiffel, Erlang, Euphoria, Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP, Pike, Pliant, Python, Ruby, Smalltalk, and Tcl.
SDL is distributed under GNU LGPL version 2. This license allows you to use SDL freely in commercial programs as long as you link with the dynamic library.
To find out more about SDL and its components see the project's website http://www.libsdl.org.
Download
The SDL library releases can be found at: http://www.libsdl.org/download-1.2.php.
The latest available release by the time of writing of this tutorial is 1.2.13 (January 05th 2001).
To download this release, just type the following command:
wget http://www.libsdl.org/release/SDL-1.2.13.tar.gz
Environment Setup
The host machine will be a PC with a GNU Linux distribution installed.
The embedded platform might be constructed on top of one of the following architectures:
- arm.
- mips.
- mipsel.
- ppc.
- sparc.
Prerequisites
To cross compile the SDL library, you need either a cross compiler, or an emulated Linux running on top of a virtualization software such as QEMU, matching your specific targeted platform.
In order to build yourself such a cross compiler, at crosstool page we introduced the way to build a C,C++ 4.1 GNU compiler for an ARM platform.
Also, hackers will be interested finding all the details to setup an ARM Debian system on their traditional Ubuntun distro following the indications quoted in this other arm-debian-on-ubuntu.
The SDL library does not need any specific dependencies.
The Cross compilation process
Option 1: Using a cross compiler
Assumptions
During the process, we will assume the cross toolchain is called xxx-yyy-linux-gnu, meaning that the gcc, g++, ar, ..., ld utilities are prefixed by xxx-yyy-linux-gnu. For example, for this toolchain the C compiler is called xxx-yyy-linux-gnu-gcc.
We will also assume that the bin, include, lib and libexec folders of the cross toolchain are accessible through the PATH variable environment in order to work with the compilers from any place in the file system.
Finally, we suppose it is intalled in the following folder: /opt/crosstool/gcc-4.1.2-glibc-2.3.2/xxx-yyy-linux-gnu.
Organization
As mentioned above:
- The release being cross compiled is:
1.2.13
- The tar.gz file will then be extracted under:
/opt/external_packages/sdl/1.2.13/source
- The results of the compilation will be stored under:
/opt/external_packages/sdl/1.2.13/compiled/xxx-yyy-linux-gnu
The files resulting from the cross compilation are listed here (the content of the share folder is intentionaly not displayed):
.: total 16 drwxr-xr-x 2 root root 4096 2008-03-10 16:18 bin drwxr-xr-x 3 root root 4096 2008-03-10 16:18 include drwxr-xr-x 3 root root 4096 2008-03-10 16:18 lib drwxr-xr-x 4 root root 4096 2008-03-10 16:18 share ./bin: total 4 -rwxr-xr-x 1 root root 1281 2008-03-10 16:18 sdl-config ./include: total 4 drwxr-xr-x 2 root root 4096 2008-03-10 16:18 SDL ./include/SDL: total 580 -rw-r--r-- 1 root root 4336 2008-03-10 16:18 begin_code.h -rw-r--r-- 1 root root 1423 2008-03-10 16:18 close_code.h -rw-r--r-- 1 root root 1875 2008-03-10 16:18 SDL_active.h -rw-r--r-- 1 root root 10879 2008-03-10 16:18 SDL_audio.h -rw-r--r-- 1 root root 910 2008-03-10 16:18 SDL_byteorder.h -rw-r--r-- 1 root root 5657 2008-03-10 16:18 SDL_cdrom.h -rw-r--r-- 1 root root 8953 2008-03-10 16:18 SDL_config.h -rw-r--r-- 1 root root 2303 2008-03-10 16:18 SDL_cpuinfo.h -rw-r--r-- 1 root root 5653 2008-03-10 16:18 SDL_endian.h -rw-r--r-- 1 root root 1762 2008-03-10 16:18 SDL_error.h -rw-r--r-- 1 root root 12564 2008-03-10 16:18 SDL_events.h -rw-r--r-- 1 root root 910 2008-03-10 16:18 SDL_getenv.h -rw-r--r-- 1 root root 3133 2008-03-10 16:18 SDL.h -rw-r--r-- 1 root root 5203 2008-03-10 16:18 SDL_joystick.h -rw-r--r-- 1 root root 3885 2008-03-10 16:18 SDL_keyboard.h -rw-r--r-- 1 root root 7160 2008-03-10 16:18 SDL_keysym.h -rw-r--r-- 1 root root 2769 2008-03-10 16:18 SDL_loadso.h -rw-r--r-- 1 root root 2732 2008-03-10 16:18 SDL_main.h -rw-r--r-- 1 root root 4689 2008-03-10 16:18 SDL_mouse.h -rw-r--r-- 1 root root 5707 2008-03-10 16:18 SDL_mutex.h -rw-r--r-- 1 root root 183 2008-03-10 16:18 SDL_name.h -rw-r--r-- 1 root root 336232 2008-03-10 16:18 SDL_opengl.h -rw-r--r-- 1 root root 2516 2008-03-10 16:18 SDL_platform.h -rw-r--r-- 1 root root 1919 2008-03-10 16:18 SDL_quit.h -rw-r--r-- 1 root root 4783 2008-03-10 16:18 SDL_rwops.h -rw-r--r-- 1 root root 15662 2008-03-10 16:18 SDL_stdinc.h -rw-r--r-- 1 root root 5991 2008-03-10 16:18 SDL_syswm.h -rw-r--r-- 1 root root 4436 2008-03-10 16:18 SDL_thread.h -rw-r--r-- 1 root root 4424 2008-03-10 16:18 SDL_timer.h -rw-r--r-- 1 root root 910 2008-03-10 16:18 SDL_types.h -rw-r--r-- 1 root root 2557 2008-03-10 16:18 SDL_version.h -rw-r--r-- 1 root root 37051 2008-03-10 16:18 SDL_video.h ./lib: total 2300 lrwxrwxrwx 1 root root 20 2008-03-10 16:18 libSDL-1.2.so.0 -> libSDL-1.2.so.0.11.2 -rwxr-xr-x 1 root root 941207 2008-03-10 16:18 libSDL-1.2.so.0.11.2 -rw-r--r-- 1 root root 1389128 2008-03-10 16:18 libSDL.a -rwxr-xr-x 1 root root 851 2008-03-10 16:18 libSDL.la -rw-r--r-- 1 root root 3318 2008-03-10 16:18 libSDLmain.a lrwxrwxrwx 1 root root 20 2008-03-10 16:18 libSDL.so -> libSDL-1.2.so.0.11.2 drwxr-xr-x 2 root root 4096 2008-03-10 16:18 pkgconfig ./lib/pkgconfig: total 4 -rw-r--r-- 1 root root 519 2008-03-10 16:18 sdl.pc
Cross Compiling
Step 1
Install the SDL library by untaring it in /opt/external_packages/sdl/1.2.13/source
folder and then cd
to this directory.
Note:
All the directories and files listed below must be moved from the SDL-1.2.13
folder
to its parent folder (/opt/external_packages/SDL/1.2.13/source
).
Directories and files:
acinclude.m4 CREDITS MPWmake.sea.bin README.NanoX README.SVN SDL.spec Watcom-OS2.zip autogen.sh CWprojects.sea.bin README README.NDS README.Symbian SDL.spec.in Watcom-Win32.zip Borland.html docs README.AmigaOS README.OS2 README.Watcom src WhatsNew Borland.zip docs.html README.BeOS README.PicoGUI README.WinCE symbian.zip Xcode.tar.gz BUGS include README.CVS README.Porting README.wscons test build-scripts INSTALL README.DC README.QNX sdl-config.in TODO configure Makefile.dc README.MacOS README.Qtopia sdl.m4 VisualCE.zip configure.in Makefile.in README.MacOSX README.RISCOS sdl.pc.in VisualC.html COPYING Makefile.minimal README.MiNT README-SDL.txt SDL.qpg.in VisualC.zip
Step 2
We want to cross compile SDL with the its default options, then we configure the software by typing the following command:
./configure --host=xxx-yyy-linux-gnu --prefix=/opt/external_packages/sdl/1.2.13/compiled/xxx-yyy-linux-gnu
Step 4
To compile and install the SDL library, type successively make
and make install
. You should find the directories and files listed above under /opt/external_packages/sdl/1.2.13/compiled/xxx-yyy-linux-gnu/
.
Option 2: Using QEMU
This section is not yet available.
Download
- arm-SDL-1.2.13-tar.gz
You may consult this section if you want to download the SDL library already cross compiled for your target platform if it is available. You can also contribute to expand the crosscompile.org community by uploading your own results in the case a given platform is not already supported.
Supported platforms
arm-unknown-linux-gnu
Written by David Sayada.