“没有可用的视频设备” SDL2 错误
这是我
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
SDL_Window *window = NULL;
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
SDL_Log("ERROR : SDL Initialization > %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
//Program
window = SDL_CreateWindow("My Viewer",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(window == NULL)
{
SDL_Log("ERROR : SDL Window creation > %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_Delay(5000);
SDL_DestroyWindow(window);
SDL_Quit();
return EXIT_SUCCESS;
}
运行命令行时的简单程序: gcc main.c -o prog $(sdl2-config --cflags --libs) && ./prog
它显示:
错误:环境中未设置 XDG_RUNTIME_DIR。
信息:错误:SDL 初始化 >没有可用的视频设备
我搜索了很多论坛并尝试了他们告诉我们的操作,但没有任何效果。
我卸载并重新安装(手动以及使用命令行)SDL2,更改环境变量“export DISPLAY=:0.0”或“export DISPLAY=:1”,尝试了这个 论坛但似乎没有任何改变。
我正在使用 WSL2 在 bash Ubuntu 中运行此代码。
Here is my simple program
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
SDL_Window *window = NULL;
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
SDL_Log("ERROR : SDL Initialization > %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
//Program
window = SDL_CreateWindow("My Viewer",SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(window == NULL)
{
SDL_Log("ERROR : SDL Window creation > %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_Delay(5000);
SDL_DestroyWindow(window);
SDL_Quit();
return EXIT_SUCCESS;
}
When running the command line :gcc main.c -o prog $(sdl2-config --cflags --libs) && ./prog
it display :
error: XDG_RUNTIME_DIR not set in the environment.
INFO: ERROR : SDL Initialization > No available video device
I search many forum and tried what they told us to do but nothing work.
I uninstall and re install (manually and also with command line) SDL2, change the env var "export DISPLAY=:0.0" or "export DISPLAY=:1", tried this forum but nothing seems to change.
I'm running this code in bash Ubuntu with WSL2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢大家,我设法用这个解决方案运行我的程序:
我没有更改任何环境变量或任何其他库。
Thank you everyone I manage to run my program with this solution :
I didn't change any env var or any other library.