4

I've installed libsdl 1.2 -dev on my Ubuntu but the problem is that it doesn't understand #include<SDL.h>

And it says:

SDL.h: No such file or directory 

But when i type:

kit0n@ubuntu:~$ g++ sepand.cpp -o sepand -lSDL 

The project compiles without any problems. What should I do to make Ubuntu understand SDL.h?

6
  • SDL.h and sdl.h are not the same thing - your code and error message don't match, please correct that. Also your question is not clear - where does it work and where doesn't it? If the g++ command you quote works, what is the problem exactly? Commented Oct 16, 2011 at 16:19
  • the problem is that it doesn't work when it's SDL.h but it works with SDL/SDL.h the problem is that i can't change the code so i have to make it work with SDL.h Commented Oct 16, 2011 at 17:23
  • 1
    Then add -I/usr/include/SDL (or wherever that include directory is located on your machine) to your compile commands (before the source file name). Commented Oct 16, 2011 at 17:24
  • IS there some way that i dont need to do it before every compile? cause this thing that i'm talking about is a program that has some functions related to SDL so i don't exactly COMPILE something i run a program Commented Oct 16, 2011 at 18:07
  • I don't understand what you are saying. Headers are only used at compile time. If you are getting that error, you're compiling something. And if you're compiling, you need to tell the compiler where the headers are. Commented Oct 16, 2011 at 18:13

1 Answer 1

6

The correct way is to add `sdl-config --cflags` to your CXXFLAGS. (You should also add `sdl-config --libs` to your LIBS even thou it doesn't seem to be needed in your case.)

Paraphrasing from the link: use the output of the command sdl-config --cflags --libs for SDL 1.2 or sdl2-config --cflags --libs for SDL2, for example:

gcc -o test test.c `sdl-config --cflags --libs` 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.