Can't run SDL(2) on Ubuntu, No available video device

故事扮演 提交于 2019-12-31 01:47:09

问题


When i try to run my program i get the following error message:

SDL could not initialize! SDL_Error: No available video device

I have all the necessary SDL libraries installed and I'm currently running ubuntu 15.10

Here is my simple SDL code:

#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;
}

The SDL2 library are correctly linked to my C project.


回答1:


This error message occurs when there is no available video driver built into SDL2 for your display system (X11, Mir, Wayland, RPI ...). Have you installed SDL2 package from Ubuntu repository or compiled from source ? When compiled from source, you should check that the supported video drivers are going to be built into the binary at the end of the "configure" step. Otherwise you need to install the required development headers (for X11 and Mir).



来源:https://stackoverflow.com/questions/36485637/cant-run-sdl2-on-ubuntu-no-available-video-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!