I'm trying to follow a tutorial using the SDL2 library. I've followed the instructions here verbatim.
The program compiles fine, but when I try to run it within eclipse I get the following error when calling SDL_Init(SDL_INIT_VIDEO)
:
No available video device
After some research I decided this was because SDL2 had not been correctly linked to any display drivers so wasted several hours installing it from source, and trying various fixes suggested on various forums.
After following another tutorial I found that there was nothing wrong with my SDL2 installation. And in fact when I run the executable created by the eclipse project from the terminal, it runs without any problems.
There are similar questions (for example here), but I can't find one where the error occurs from within eclipse, but not the terminal.
Any pointers would be greatly appreciated. I suspect it may be to do with an environment variable not being set, but not sure which or why. Based on answers on SO I added the DISPLAY
environment variable and set it to :0
in the project set-up but with no luck.
Update: I found a way to quickly add all of my bash environment variables to my eclipse project and I still get the No available video device
error.
Update 2: Turns out I wasn't adding environment variables in the right place (I was adding them to the C++ build environment, not the Run environment; which is obviously where the problem was giving application was building but not running). Posted answer below.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…