分享

Ubuntu安装SDL-CSDN博客

 netouch 2024-02-18 发布于北京

下载

wcx@wcx:~/Downloads$ git clone https://github.com/libsdl-org/SDL.git -b SDL2
Cloning into 'SDL'...
remote: Enumerating objects: 144597, done.
remote: Counting objects: 100% (240/240), done.
remote: Compressing objects: 100% (125/125), done.
^Zceiving objects:  11% (16639/144597), 6.78 MiB | 2.50 MiB/s
[1]+  Stopped                 git clone https://github.com/libsdl-org/SDL.git -b SDL2

wcx@wcx:~/Downloads$ cd SDL/

wcx@wcx:~/Downloads/SDL$ mkdir build

wcx@wcx:~/Downloads/SDL/build$ sudo ../configure --prefix=/usr/local/ffmpeg/ --enable-shared --enable-video-x11 --enable-x11-shared --enable-video-x11-vm
configure: WARNING: unrecognized options: --enable-video-x11-vm
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no


wcx@wcx:~/Downloads/SDL/build$sudo make -j4
mkdir -p -- gen
mkdir -p -- gen
mkdir -p -- gen
mkdir -p -- gen

安装

wcx@wcx:~/Downloads/SDL/build$ sudo make install
/bin/bash ../build-scripts//updaterev.sh --vendor ""
/bin/bash ../build-scripts//mkinstalldirs /usr/local/ffmpeg/bin
/usr/bin/install -c -m 755 sdl2-config /usr/local/ffmpeg/bin/sdl2-config
/bin/bash ../build-scripts//mkinstalldirs /usr/local/ffmpeg/include/SDL2
mkdir -p -- /usr/local/ffmpeg/include/SDL2
for file in SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_bits.h SDL_blendmode.h SDL_clipboard.h SDL_cpuinfo.h SDL_egl.h SDL_endian.h SDL_error.h SDL_events.h SDL_filesystem.h SDL_gamecontroller.h SDL_gesture.h SDL_guid.h SDL_haptic.h SDL_hidapi.h SDL_hints.h SDL_joystick.h SDL_keyboard.h SDL_keycode.h SDL_loadso.h SDL_locale.h SDL_log.h SDL_main.h SDL_messagebox.h SDL_metal.h SDL_misc.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_opengl_glext.h SDL_opengles.h SDL_opengles2_gl2ext.h SDL_opengles2_gl2.h SDL_opengles2_gl2platform.h SDL_opengles2.h SDL_opengles2_khrplatform.h SDL_pixels.h SDL_platform.h SDL_power.h SDL_quit.h SDL_rect.h SDL_render.h SDL_rwops.h SDL_scancode.h SDL_sensor.h SDL_shape.h SDL_stdinc.h SDL_surface.h SDL_system.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_touch.h SDL_types.h SDL_version.h SDL_video.h SDL_vulkan.h begin_code.h close_code.h SDL_test_assert.h SDL_test_common.h SDL_test_compare.h SDL_test_crc32.h SDL_test_font.h SDL_test_fuzzer.h SDL_test.h SDL_test_harness.h SDL_test_images.h SDL_test_log.h SDL_test_md5.h SDL_test_memory.h SDL_test_random.h; do     /usr/bin/install -c -m 644 /home/wcx/Downloads/SDL/include/$file /usr/local/ffmpeg/include/SDL2/$file; done
/usr/bin/install -c -m 644 include/SDL_config.h /usr/local/ffmpeg/include/SDL2/SDL_config.h
if test -f include/SDL_revision.h; then     /usr/bin/install -c -m 644 include/SDL_revision.h /usr/local/ffmpeg/include/SDL2/SDL_revision.h; else     /usr/bin/install -c -m 644 /home/wcx/Downloads/SDL/include/SDL_revision.h /usr/local/ffmpeg/include/SDL2/SDL_revision.h; fi
/bin/bash ../build-scripts//mkinstalldirs /usr/local/ffmpeg/lib
/bin/bash ./libtool --quiet --mode=install /usr/bin/install -c build/libSDL2.la /usr/local/ffmpeg/lib/libSDL2.la
/bin/bash ./libtool --quiet --mode=install /usr/bin/install -c build/libSDL2main.la /usr/local/ffmpeg/lib/libSDL2main.la
/bin/bash ./libtool --quiet --mode=install /usr/bin/install -c build/libSDL2_test.la /usr/local/ffmpeg/lib/libSDL2_test.la
/bin/bash ../build-scripts//mkinstalldirs /usr/local/ffmpeg/share/aclocal
/usr/bin/install -c -m 644 /home/wcx/Downloads/SDL/sdl2.m4 /usr/local/ffmpeg/share/aclocal/sdl2.m4
/bin/bash ../build-scripts//mkinstalldirs /usr/local/ffmpeg/lib/pkgconfig
/usr/bin/install -c -m 644 sdl2.pc /usr/local/ffmpeg/lib/pkgconfig
/bin/bash ../build-scripts//mkinstalldirs /usr/local/ffmpeg/lib/cmake/SDL2
mkdir -p -- /usr/local/ffmpeg/lib/cmake/SDL2
/usr/bin/install -c -m 644 sdl2-config.cmake /usr/local/ffmpeg/lib/cmake/SDL2
/usr/bin/install -c -m 644 sdl2-config-version.cmake /usr/local/ffmpeg/lib/cmake/SDL2

例子:

#include <SDL2/SDL.h>  
#include <stdio.h>  
  
int main(int argc, char *argv[]) {  
    SDL_Init(SDL_INIT_VIDEO);  
    printf("SDL initialized\n");  
    SDL_Quit();  
    printf("SDL quit\n");  
    return 0;  
}

Cmake 编译运行

CMakeLists.txt


cmake_minimum_required(VERSION 3.0)
# 设置项目名称
project(MyProject)
set(CMAKE_CXX_STANDARD 17)
include_directories( 
    /usr/local/ffmpeg/include 
    )

link_directories(
    /usr/local/ffmpeg/lib
    )
add_executable(test TestSDL.cpp)
target_link_libraries(test X11 dl pthread SDL2)

wcx@wcx:~/Desktop/gdb_test/build$ sudo cmake ..
[sudo] password for wcx: 
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- C compiler: /usr/bin/cc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wcx/Desktop/gdb_test/build

wcx@wcx:~/Desktop/gdb_test/build$ sudo make 
Scanning dependencies of target wcx
[ 50%] Building CXX object CMakeFiles/wcx.dir/TestSDL.cpp.o
[100%] Linking CXX executable wcx
[100%] Built target wcx

wcx@wcx:~/Desktop/gdb_test/build$ ./test 
SDL initialized
SDL quit

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多