Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'"SDL.h" no such file or directory found' when compiling

Tags:

c++

linux

sdl

Here's a piece of my current Makefile:

CFLAGS = -O2 -Wall -pedantic -std=gnu++11 `sdl-config --cflags --libs` -lSDL_mixer 

I have libsdl installed properly, SDL.h is in /usr/include/sdl where it belongs, but it just won't compile. I also have the line #include "SDL.h" in my .h files, but still no go.

Anyone knows why?

like image 432
argoneus Avatar asked May 07 '12 20:05

argoneus


People also ask

Where is SDL h in Linux?

h is in /usr/include/sdl where it belongs, but it just won't compile.

How to include SDL on linux?

Debian-based systems (including Ubuntu) can simply do "sudo apt-get install libsdl2-2.0" to get the library installed system-wide, and all sorts of other useful dependencies, too. "sudo apt-get install libsdl2-dev" will install everything necessary to build programs that use SDL.

What is SDL SDL H?

SDL is Simple DirectMedia Layer.It is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.It can be used to make animations and video games.


2 Answers

For Simple Direct Media Layer 2 (SDL2), after installing it on Ubuntu 16.04 via:

sudo apt-get install libsdl2-dev 

I used the header:

#include <SDL2/SDL.h>   

and the compiler linker command:

-lSDL2main -lSDL2  

Additionally, you may also want to install:

apt-get install libsdl2-image-dev   apt-get install libsdl2-mixer-dev   apt-get install libsdl2-ttf-dev   

With these headers:

#include <SDL2/SDL_image.h> #include <SDL2/SDL_ttf.h> #include <SDL2/SDL_mixer.h>   

and the compiler linker commands:

-lSDL2_image  -lSDL2_ttf  -lSDL2_mixer 
like image 192
StackAttack Avatar answered Sep 19 '22 21:09

StackAttack


If the header file is /usr/include/sdl/SDL.h and your code has:

#include "SDL.h" 

You need to either fix your code:

#include "sdl/SDL.h" 

Or tell the preprocessor where to find include files:

CFLAGS = ... -I/usr/include/sdl ... 
like image 36
larsks Avatar answered Sep 17 '22 21:09

larsks