SDL 2.0 won't initialize. Error: “Failed to connect to the Mir Server”

前端 未结 3 736
春和景丽
春和景丽 2021-01-20 04:17

I am running Ubuntu 14.04, and using Eclipse CDT.

In my program, I am trying to initialize SDL and if it doesn\'t initialize then output the error, but SDL_GetError(

3条回答
  •  天涯浪人
    2021-01-20 04:43

    bash$ export DISPLAY=:0

    Setting the DISPLAY run time environment variable fixes it for me — typical X Windows lossage, fails to default to your local display (designed for remote displays) which you'd only know if you'd gone to X11 summer camp.

    A complete working example in bash:

    (cd /tmp && g++ -xc++ - -lSDL2 && (DISPLAY=:0 ./a.out; echo \$? = $?)) <<.
    #include 
    #include 
    
    int main() {
      if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        std::cout << SDL_GetError() << std::endl;
        return 1;
      }
      return 0;
    }
    .
    

    $? = 0

提交回复
热议问题