【发布时间】:2016-04-07 19:37:47
【问题描述】:
当我尝试运行我的程序时,我收到以下错误消息:
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 项目。
【问题讨论】:
-
你能得到这个工作吗?你是在eclipse中运行它吗?我有一个非常相似的问题,但请注意,我可以毫无问题地从终端运行可执行文件。
-
如果您在 Eclipse 中运行,您很有可能遇到与我相同的问题。请参阅here 发布的答案。