How are you compiling the program that throws the error?
Knowing archlinux, sdl2 is required by a lot of other programs including ffmpeg, so I’m guessing it’s installed. if it’s not do sudo pacman -S sdl2
. You can also do pacman -Fl sdl2
to list out all the files that are installed and pacman -Fl sdl2 | grep SDL.h
will get the path where the header files are installed.
if your building from source, just do sudo make install
. If you don’t want to install it, create a shell script or something with the name sdl2-config which outputs the appropriate flags that you need and place it on your PATH before the other sdl2-config.
Don’t really bother to statically link it (at least for linux) because sdl is available at pretty much every distro. Then use this command to compile source.c
.
cc source.c `sdl2-config --cflags`
The source code for source.c
#include "SDL.h"
int main(){}
You could also do cc source.c -I<SDL_INCLUDE_DIR>
where <SDL_INCLUDE_DIR>
is replaced with the appropriate directory that contains SDL.h. Though I do not recommend this because it might not be the same in different distros / environment. sdl2-config
and pkg-config
provide a convenient way to pass the required flags for a library to the compiler that can be changed by the distro maintainers when needed.
if this works it might be a problem with your build system.
Otherwise, look at what sdl2-config actually outputs by doing sdl2-config --cflags
on it’s own without using it for command substitution. If it outputs the same error, compare what’s given by sdl2-config with the -I
flag and compare it to the directory where the SDL2 include directory is located. See if the directory actually exists and that there’s a SDL.h file in there.
I’ll also encourage you to learn the c compilation process. Learn the c preprocessor, compiling (creating an object file) and linking. Learning assembly may help. In your case the problem was at the preprocessing stage and can be reproduced by doing cpp source.c
or cc -E source.c
. By the way, there’s no reason for you to try #include <file.h>
after doing #include "file.h"
since the former only searches in predefined directories while the latter searches in the directory the header was included from and in the predefined directories.
Also, next time when you ask try to give more information like the command used to compile and try to give the smallest possible test case where the problem can be replicated. Without knowing what you did, we can’t replicate it and can’t really help you. If you’re wondering why this reply is long, it’s because I can’t really assume anything since you didn’t give enough information.
Possibly helpful links:
http://catb.org/~esr/faqs/smart-questions.html