Building the SDL development environment

Source: Internet
Author: User

SDL (Simple DirectMedia Layer) is a set of open source cross-platform multimedia development libraries, written in C language. SDL provides several functions for controlling images, sounds, and outputs so that developers can develop applications across multiple platforms (Linux, Windows, Mac OS x, etc.) with the same or similar code. SDL is currently used to develop multimedia applications such as games, simulators, media players, and more.

First, Win7 platform

The development tool used is vs2013.

    • Download the SDL Development Library from http://www.libsdl.org/download-2.0.php, such as:

Download Get sdl2-devel-2.0.3-vc.zip, unzip:

Under include is SDL's header file, under Lib/x86 is the SDL dynamic library and Static library for 32-bit platforms, where we use only the x86 platform's library files.

    • New Console Project

Open VC + +
FILE-New Project->win32 Console application

    • Copy SDL Development files

The header file (*.h) is copied to the include subfolder of the project folder
The Import library file (*.lib) is copied to the Lib subfolder of the project folder, such as:


Copy the dynamic library file (*.dll) to C:\Windows\system

    • Configuring Development Files

Open the Properties panel
Right-click Project-Properties, Solution Explorer

      • Header file Configuration

Configuration Properties->c/c++-> General, additional include directories, enter "include" (the directory where you just copied the files)

      • Import library Configuration

Configuration Properties----general----add-in library directory with linker, type "Lib" (the directory where you just copied the file)
Configuration properties, linker, input, additional dependencies, input "SDL2.lib; SDL2main.lib; SDL2test.lib "(The file name of the import library)
Dynamic libraries are not configured

    • Test
      • Create a source code file

In the project, create a C + + file that contains the main () function (if you already have one, you can skip this step), and then write the source code in the file in the next steps.

      • Include header file

If you are using SDL in the C language, use the following code directly
#include "SDL.h"
If you are using SDL in the C + + language, use the following code

extern " C "  "sdl2/sdl.h"}
      • Test program

For example, the following code initializes the SDL

 int  Main (int  argc,  argv[]) { if   (Sdl_init (Sdl_init_video)) {printf (  " could not initialize SDL-%s\n   "     else  {printf (  " success init SDL  "  );  return  0  ;}

Operation Result:

Second, Ubuntu14.04
    • Download SDL source code from http://www.libsdl.org/download-2.0.php,:

Unzip, execute the following command

TAR-XF sdl2-2.0. 3 . Tar.gzmkdir BUILDCD Build : /sdl2-2.0. 3/configuremakesudo make install

The default is to put the generated header files, the static libraries, and the dynamic inventory under/usr/local/include/and/usr/local/lib, or you can set the--prefix to/usr/when configure.

If you install Ld_library_path under/usr/local, you can add the following command to the. BASHRC:

Export Ld_library_path= $LD _library_path:/usr/local/lib
    • Test

Makefile

inc=-i/usr/local/includelib_dir=-l/usr/local/liblib=-lsdl2demo:demo.o    gcc   $^-o [email protected] $ (INC) $ (lib_dir) $ (LIB) Demo.o:demo.cclean:    RM *.O Demo

Demo.c

#include <stdio.h>#include<SDL2/SDL.h>intMainintargcConst Char*argv[]) {    if(Sdl_init (Sdl_init_video)) {printf ("Could not initialize SDL-%s\n", Sdl_geterror ()); }    Else{printf ("Success Init sdl\n"); }    return 0;}

Perform:

[email protected]:~/study/video/sdl/demo#./demo Success init SDL

Finish.

Building the SDL development environment

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.