1 Download and install
To http://www.libsdl.org/download Http://www.libsdl.org/release/SDL2-2.0.3.zip source code
After decompression
./configure
Make
sudo make install
Check
Header file:/USR/LOCAL/INCLUDE/SDL2
Library Location:/usr/local/lib
2 Establishing the test procedure:
#include <iostream> #include <SDL.h> #define WIDTH 640#define HEIGHT 480#define BPP 4#define DEPTH 32using Name Space Std;int Main (int argc, char* argv[]) {sdl_surface *screen; Sdl_event Event; int keypress = 0; int h = 0; if (Sdl_init (sdl_init_everything) = =-1) {cout << "error:" << sdl_geterror () << Endl; return 1; } sdl_window* Window = Sdl_createwindow ("Hello", sdl_windowpos_centered, sdl_windowpos_centered, 640, 480, SDL_WIND Ow_shown); if (window = = NULL) {cout << "Error:" << sdl_geterror () << Endl; return 1; }sdl_renderer* Renderer = sdl_createrenderer (window,-1, sdl_renderer_accelerated | Sdl_renderer_presentvsync); if (renderer = = NULL) {cout << "Error:" << sdl_geterror () << Endl; return 1; }sdl_surface* Surface = sdl_loadbmp ("Bk.bmp"); sdl_texture* Texture = sdl_createtexturefromsurface (renderer, surface); Sdl_freesurface (surface); Sdl_renderClear (renderer); Clear Screen sdl_rendercopy (renderer, texture, 0, 0); Draw the texture to the renderer sdl_renderpresent (renderer); while (!keypress) {//drawscreen (screen, h++); while (Sdl_pollevent (&event)) {switch (event.type) {case Sdl_quit: KeyPress = 1; Break Case sdl_keydown:keypress = 1; Break }}} sdl_quit (); return 0;}
3 Write the compiled command build file, as follows:
g++ Sdl_app1.cpp-i/usr/local/include/sdl2-l/usr/local/lib-lsdl2-lpthread
To set execution permissions for this file:
chmod +x Build
Run the Compile command:
./build
Generate Execution File a.out
4 Running the program
./a.out
If you cannot find the. so.0 ..., the case where the dynamic link library cannot be found
To run the command:
sudo vim/etc/ld.so.conf #修改系统共享库搜索路径
Increase in the first line
Include/usr/local/lib
Run the command again:
sudo ldconfig
Run./a.out
The results are working correctly
C + + Development SDL2 application under Ubuntu14.04