Trying to get SDL2 to work with C++ on a Raspberry Pi 3B+ but don’t know how to get it to link to the SDL2 libraries.
Not hugely familiar with Linux.
I installed SDL2 as follows:
sudo apt-get install libsdl2-2.0-0. Says it is already installed.
sudo apt-get install libsdl2-dev.
Then I created the folder /home/pi/C++/SDL2Test1.
Using geany I wrote the following code and saved it to SDL2Test1.cpp:
#include <stdio.h>
#include "SDL2/SDL.h"
int main( int argc, char* args[] )
{
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
printf( "SDL could not be initialized! SDL_Error= %s\n", SDL_GetError() );
}
else {
puts( "SDL initialized OK!" );
}
return 0;
}
I set up the build command to do this:
g++ -Wall -std=c++0x -lSDL2 SDL2Test1.cpp -oSDL2Test1
Then I did a build, and got this:
Ignore the warnings. It failed to link to the SDL2 library.
What do I need to do to fix this? I’m not entirely certain which folder contains the SDL2 library. If I knew then I was thinking that I could do this:
cd ~
nano .profile
then go to the end of the file and add something like this:
PATH="/lib/SDL2:$PATH"
but I cannot figure out the folder I need to specify.
It would be nice to modify the INCLUDE environment variable as well, so I could just use:
#include "SDL.h"
instead of
#include "SDL2/SDL.h"
but that’s a minor annoyance.
I feel like there is something else I needed to do after installing SDL2 to make it work more smoothly with g++, but I don’t see anything in the tutorials I have followed.
So:
- Is this the correct approach?
- Where is the SDL library folder so I can include it in the PATH?
- How do I specify where to find include files?
Any help appreciated.
