I downloaded SDL2-2.0.3
. I ran ./configure && make && make install
.
I\'ve also tried brew install SDL2
.
The following command is installed along with SDL and it tells you the correct switches for compiling and linking:
sdl2-config --cflags --libs
On my particular machine, that gives:
-I/usr/local/include/SDL2 -D_THREAD_SAFE
-L/usr/local/lib -lSDL2
That means you can compile and link like this and always be assured of getting the correct settings:
g++ main.cpp -o main $(sdl2-config --cflags --libs)
Or, you can put it in a Makefile like this (with a TAB at the start of the second line):
main: main.cpp
g++ main.cpp -o main $$(sdl2-config --cflags --libs)
Make sure you download the x64 SDL2 version. You also need to statically link it with -lSDL2
flag.
You are failing to link with libSDL2.{a,dylib}
.
You want:
gcc -o main main.c -lSDL2
or perhaps:
gcc -o main main.c -L/usr/local/lib -lSDL2
You need to run
sdl2-config --cflags
which will give you the compile flags, andsdl2-config --libs
which will give you the linker flagsneeded for using SDL2.
The flags will vary by platform which is why you should use sdl2-config
instead of hardcoding some specific flags into your Makefile or other build script.