“没有可用的视频设备” SDL2 错误

发布于 2025-01-12 22:00:53 字数 1185 浏览 3 评论 0原文

这是我

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2025-01-19 22:00:53

谢谢大家,我设法用这个解决方案运行我的程序:

  • 安装Windows 11(因为Windows 10无法运行图形应用程序)。

此时,bash.exe中运行了以下内容

  • 安装Xming并运行Xming。 (您可以通过安装 xterm 来尝试运行 xeyes 以检查它是否正常工作)
  • 对于 SDL,只需正常安装 sdl (sudo apt-get install libsdl2-2.0)
  • 运行您的程序。

我没有更改任何环境变量或任何其他库。

Thank you everyone I manage to run my program with this solution :

  • Install Windows 11 (because Windows 10 is not able to run graphical app).

At This point, the following is run in the bash.exe

  • Install Xming and run Xming. (you can try running xeyes by installing xterm to check if it's working)
  • For SDL, just install sdl normally (sudo apt-get install libsdl2-2.0)
  • Run your program.

I didn't change any env var or any other library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文