Cross-compiling SDL for uCLinux

Source: Internet
Author: User
For uCLinux cross-compiling SDL-general Linux technology-Linux programming and kernel information, see the following for details. 1 prepare
First, install the uCLinux tool chain represented by arm-elf-gcc. The arm-elf-gcc version I use is 2.95.3. Secondly, prepare the SDL source code package, the source code version of sdl I used is 1.2.5. Finally, you have to run uCLinux on the development board. By the way, the Development Board I used is 7.7.

Assuming that the root directory of the SDL source code after decompression is/home/rockins/SDL/SDL-1.2.5/, the installation directory is set to/home/rockins/SDL/SDL-1.2.5/uclinux-build. On your system, the two directories should be different based on the actual situation.

2 configure
Because the development board I use is 7.7, many functions are useless, and these chicken ribs are directly disabled in the configure stage. As for which features may not be used, I am bold enough to guess. In view of this, some of these disabled functions may be "mistaken", but in any case, I hold the opinion that "I would rather kill one thousand by mistake and never let it go ". The final result is that only some of the most basic functions are retained. The following command runs the configure script on the console:

. /Configure -- prefix =/home/rockins/SDL/SDL-1.2.5/uclinux-build -- enable-shared = no -- enable-audio = no -- enable-joystick = yes -- enable-cdrom = no -- enable-threads = no -- enable-timers = yes -- enable-endian = yes -- enable-file = yes -- enable-esd = no -- enable-arts = no -- enable- nas = no -- enable-diskaudio = no -- enable-mintaudio = no -- enable-nasm = no -- enable-video-x11 = no -- enable-dga = no -- enable-video-x11-vm = no -- enable-video-x11-dgamouse = no -- enable-video-x11-xv = no -- enable-video-x11-xinerama = no -- enable-video-x11-xme = no -- enable-video-dga = no -- enable-video-photon = no -- enable-video-directfb = no -- enable-video-ps2gs = no -- enable-video-xbios = no -- enable-video-gem = no -- enable-video-opengl = no -- enable-pth = no -- enable-pthreads = no -- enable-pthread- sem = no

Brief description:

L -- Prefix =/home/rockins/SDL/SDL-1.2.5/uclinux-build

Specify the compiled installation directory and set it as needed.

L -- Enable-shared = no

Currently, dynamic shared libraries cannot be compiled. Therefore, you must disable dynamic shared libraries.

3 make

To compile SDL, you only need to enter the following command on the console:

Make-e CC = arm-elf-gcc CXX = arm-elf-g ++ CCAS = arm-elf-gcc CCLD = arm-elf-gcc RANLIB = arm-elf-ranlib OBJDUMP = arm-elf-objdump AR = arm-elf-ar

These parameters actually control the corresponding variables in Makefile. After replacing the source code with the arm-elf toolchain, we use the arm-elf tool to cross-compile the source code of SDL. The generated SDL function library (which is a static link library in this article) can be linked to the program code and run on the uCLinux platform.

4 test

Some test routines used to test SDL are in the/home/rockins/SDL/SDL-1.2.5/test/directory. The test routine selected in this article is testver. c. Its source code is as follows:

/* Test program to compare the compile-time version of SDL with the linked

Version of SDL

*/



# Include



# Include "SDL. h"

# Include "SDL_byteorder.h"



Int main (int argc, char * argv [])

{

SDL_version compiled;



/* Initialize SDL */

If (SDL_Init (0) <0 ){

Fprintf (stderr, "Couldn't initialize SDL: % s \ n", SDL_GetError ());

Exit (1 );

}

# Ifdef DEBUG

Fprintf (stderr, "SDL initialized \ n ");

# Endif

# If SDL_VERSION_ATLEAST (1, 2, 0)

Printf ("Compiled with SDL 1.2 or newer \ n ");

# Else

Printf ("Compiled with SDL older than 1.2 \ n ");

# Endif

SDL_VERSION (& compiled );

Printf ("Compiled version: % d. % d. % d \ n ",

Compiled. major, compiled. minor, compiled. patch );

Printf ("Linked version: % d. % d. % d \ n ",

Sdl_cmd_version ()-> major,

Sdl_cmd_version ()-> minor,

Sdl_cmd_version ()-> patch );

Printf ("This is a % s endian machine. \ n ",

(SDL_BYTEORDER = SDL_LIL_ENDIAN )? "Little": "big ");

SDL_Quit ();

Return (0 );

}

Use the following command to compile the program:

Arm-elf-gcc-o testver. c-I/home/rockins/SDL/SDL-1.2.5/uclinux-build/include/SDL/-L/home/rockins/SDL/SDL-1.2.5/uclinux-build/lib/-elf2flt? LSDL

Note that the-elf2flt option must be added when compiling this program; otherwise, the following error may occur:

Undefined reference to '_ CTOR_LIST __'

Undefined reference to '_ DTOR_LIST __'

In fact, this is not only required when compiling the testver. c program. This option must be added when compiling other programs running on the uCLinux platform. Otherwise, the above error will occur. Generally, libgcc. a contains the _ CTOR_LIST _ and _ DTOR_LIST _ symbols. However, in the toolchain of uCLinux, for some purpose, the two symbols are deleted, so the error of symbol reference cannot be found during direct compilation. Fortunately, these two symbols are provided in elf2flt's link script. Therefore, when using uCLinux tool chain to compile executable programs, you must add the-elf2flt option.

To put it bluntly, after the testver program is compiled, it can be downloaded to the Development Board through ftp, nfs, or other such means, you will see that the program prints the version information used during SDL compilation and execution. This indicates that your SDL static Link Library has been compiled successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.