12

I am trying to practice lesson_1 at https://tutorialsplay.com/opengl/2014/04/23/textured-cube/

When I run the code named cube.c I got

cube.c:16:21: fatal error: SDL/SDL.h: No such file or directory
 #include <SDL/SDL.h>
                     ^

compilation terminated.

I've installed SDL2 with guidance at https://github.com/PluginIO/EX3/wiki/Setting-up-SDL2-in-Ubuntu-12.10

I am using 14.04 though..

The installation of SDL2 was successful I did not get any error.

The SDL.h file is located in "/usr/local/include/SDL2"

I tried to force to use fullpath linking by command

gcc cube.c -lglut -lGL -lGLU -l/usr/local/include/SDL2

instead of

gcc cube.c -lglut -lGL -lGLU -lSDL

But all were in vain...

Does anybody know solution for this linking problem?

As what muru pointed out I changed to captial i got "error: unknown type name ‘SDL_keysym’" meaning worked.

Other way I discovered was

I changed

#include <SDL/SDL.h> 

to

#include <SDL2/SDL.h>

No longer shows "fatal error: SDL/SDL.h: No such file or directory" Thus for now consider solved. However I am getting the following errors that will be posting on separate thread.

cube.c:105:22: error: unknown type name ‘SDL_keysym’
 void handleKeyPress( SDL_keysym *keysym )
                      ^
cube.c: In function ‘main’:
cube.c:239:5: error: unknown type name ‘SDL_VideoInfo’
     const SDL_VideoInfo *videoInfo;
     ^

A.B.: I pasted output of your suggested commands below.

gcc cube.c `pkg-config --cflags --libs sdl`
Package sdl was not found in the pkg-config search path.
Perhaps you should add the directory containing `sdl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'sdl' found



gcc cube.c `pkg-config --cflags --libs sdl2`
cube.c:105:22: error: unknown type name ‘SDL_keysym’
 void handleKeyPress( SDL_keysym *keysym )
                      ^
cube.c: In function ‘main’:
cube.c:239:5: error: unknown type name ‘SDL_VideoInfo’
     const SDL_VideoInfo *videoInfo;
     ^
errors continue....
Evan S
  • 377
  • 3
    -l is a linker option. To add include directories, use -I (capital i). Also, why didn't you just install libsdl1.2-dev? – muru May 20 '15 at 21:57
  • @muru: Thanks for the pointing that out. I changed to captial i got "error: unknown type name ‘SDL_keysym’" meaning worked. I will post the errors on separate thread. Your second question's answer is at http://askubuntu.com/questions/626230/compile-error-usr-bin-ld-cannot-find-lsdl-collect2 – Evan S May 21 '15 at 01:15
  • @muru: can you post your solution to the answer? So that I can select the asnwer. – Evan S May 21 '15 at 01:30

1 Answers1

16

Probably you have already installed the libraries, I show the steps but again for the reason of completeness.

  • SDL2

    sudo apt-get install libsdl2-dev
    
  • SDL1

    sudo apt-get install libsdl1.2-dev
    

Start the compilation with:

  • SDL2

    gcc cube.c `pkg-config --cflags --libs sdl2`
    
  • SDL1

    gcc cube.c `pkg-config --cflags --libs sdl`
    

Sample output:

% pkg-config --cflags --libs sdl               
-D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL -lSDL

% pkg-config --cflags --libs sdl2
-D_REENTRANT -I/usr/include/SDL2 -lSDL2
A.B.
  • 90,397
  • Thank for your answer A.B.! Actually I am having issue with install libsdl1 and 2. Please comment on http://askubuntu.com/questions/626230/compile-error-usr-bin-ld-cannot-find-lsdl-collect2 I pasted output of your suggestion on question. – Evan S May 21 '15 at 14:17
  • for me sudo apt-get install libsdl1.2-dev worked not the former :) Thanks! – Mona Jalal Feb 16 '17 at 00:28