当我尝试运行我的程序时,我收到以下错误消息:
SDL could not initialize! SDL_Error: No available video device
我已经安装了所有必要的 SDL 库,我目前正在运行 ubuntu 15.10
这是我的简单 SDL 代码:
#include <stdio.h>
#include "SDL2/SDL.h"
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char* argv[])
{
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
}
else
{
//Create window
window = SDL_CreateWindow("SDL Tutorial",SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (window == NULL) {
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
}
}
return 0;
}
SDL2 库已正确链接到我的 C 项目。
最佳答案
当 SDL2 中没有适用于您的显示系统(X11、Mir、Wayland、RPI ...)的可用视频驱动程序时,会出现此错误消息。 您是从 Ubuntu 存储库安装 SDL2 软件包还是从源代码编译?从源代码编译时,您应该检查支持的视频驱动程序是否将在“配置”步骤结束时内置到二进制文件中。否则,您需要安装所需的开发头文件(用于 X11 和 Mir)。
关于无法在 Ubuntu 上运行 SDL(2),没有可用的视频设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36485637/