首页 > 解决方案 > SDL 中没有可用的视频设备

问题描述

我使用的 SDL-2 库是从源代码编译的。

每当我尝试在 X11 上运行任何使用 SDL-2 的程序时,都会出现以下错误:

SDL_Init Error: No available video device

我在 Linux Mint 19.3 Tricia 上通过命令行运行这些程序。

这是./configure摘要:

SDL2 Configure Summary:
Building Shared Libraries
Building Static Libraries
Enabled modules : atomic audio video render events joystick haptic sensor power filesystem threads timers file loadso cpuinfo assembly
Assembly Math   : mmx 3dnow sse sse2 sse3
Audio drivers   : disk dummy oss
Video drivers   : dummy opengl_es2 vulkan
Input drivers   : linuxev linuxkd
Using libsamplerate : NO
Using libudev       : NO
Using dbus          : NO
Using ime           : YES
Using ibus          : NO
Using fcitx         : NO

标签: c++clinuxsdlsdl-2

解决方案


看起来您的 SDL 构建缺少 X11 后端。

Mint 看起来足够 Debian-y,sudo apt build-dep libsdl2应该引入所需的-dev软件包。然后您可以重新运行./configure和重建/重新安装 SDL。

确保仔细检查摘要中的Video driversconfigure是否包含您有兴趣使用的后端。

如果该build-dep方法过于手动,则docs/README-linux.md有一个(有点旧的)逐项列出的-dev包列表:

================================================================================
Build Dependencies
================================================================================

Ubuntu 13.04, all available features enabled:

sudo apt-get install build-essential mercurial make cmake autoconf automake \
libtool libasound2-dev libpulse-dev libaudio-dev libx11-dev libxext-dev \
libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev \
libxss-dev libgl1-mesa-dev libesd0-dev libdbus-1-dev libudev-dev \
libgles1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libibus-1.0-dev \
fcitx-libs-dev libsamplerate0-dev libsndio-dev

Ubuntu 16.04+ can also add "libwayland-dev libxkbcommon-dev wayland-protocols"
to that command line for Wayland support.

NOTES:
- This includes all the audio targets except arts, because Ubuntu pulled the 
  artsc0-dev package, but in theory SDL still supports it.
- libsamplerate0-dev lets SDL optionally link to libresamplerate at runtime
  for higher-quality audio resampling. SDL will work without it if the library
  is missing, so it's safe to build in support even if the end user doesn't
  have this library installed.
- DirectFB isn't included because the configure script (currently) fails to find
  it at all. You can do "sudo apt-get install libdirectfb-dev" and fix the 
  configure script to include DirectFB support. Send patches.  :)

推荐阅读