Search code examples
cubuntusdlx11

SDL2 is not seeing X11/Video Device correctly


(I am aware there is a great deal of documentation on the subject, but I am either too inexperienced to find the one that works or I have a different problem than the one documented)

I am trying to load up a simple SDL wrapper that I wrote on my Mac on Linux (Lubuntu 20.04, LXQt 0.14.1). However when SDL_Init(SDL_INIT_VIDEO) is called, the following SDL_Error() return statement is generated: No available video device. I have verified that my DISPLAY envvar is set to :0 (which is correct according to xterm) and my SDL_VIDEODRIVER is unset.

Setting my SDL_VIDEODRIVER to x11 triggers this alternative error on init x11 not available.

I am rather stumped, the only possible conclusion I could draw from this is that I am somehow not using x11 or am going about this wrong.

Here is a minimal example that triggers this error:

#include <SDL2/SDL.h>

int main() {
    SDL_Init(SDL_INIT_VIDEO);
    printf("%s\n", SDL_GetError());
}

I really appreciate any help I can get!

I am using the libsdl2-dev apt package for SDL2


Solution

  • Turns out that I had forgotten to link X11 during compilation which caused SDL_VIDEO to fail to initialise. This was resolved by using -lX11.

    Thank you for the help!