
我正在嘗試練習 Lesson_1 https://tutorialsplay.com/opengl/2014/04/23/textured-cube/
當我運行名為cube.c的程式碼時,我得到了
cube.c:16:21: fatal error: SDL/SDL.h: No such file or directory
#include <SDL/SDL.h>
^
compilation terminated.
我已經在指導下安裝了 SDL2 https://github.com/PluginIO/EX3/wiki/Setting-up-SDL2-in-Ubuntu-12.10
不過我用的是14.04..
SDL2的安裝成功,我沒有收到任何錯誤。
SDL.h 檔案位於“/usr/local/include/SDL2”
我試圖透過命令強制使用完整路徑鏈接
gcc cube.c -lglut -lGL -lGLU -l/usr/local/include/SDL2
代替
gcc cube.c -lglut -lGL -lGLU -lSDL
但一切都是徒勞…
有人知道這個連結問題的解決方案嗎?
正如穆魯指出的那樣,我更改為大寫,我得到“錯誤:未知類型名稱'SDL_keysym'”,意思是有效。
我發現的另一種方式是
我變了
#include <SDL/SDL.h>
到
#include <SDL2/SDL.h>
不再顯示“致命錯誤:SDL/SDL.h:沒有這樣的檔案或目錄”因此現在考慮解決。但是我收到以下錯誤,這些錯誤將發佈在單獨的線程上。
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;
^
AB:我在下面貼上了您建議的命令的輸出。
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....
答案1
也許您已經安裝了這些庫,出於完整性考慮,我再次展示了這些步驟。
SDL2
sudo apt-get install libsdl2-dev
SDL1
sudo apt-get install libsdl1.2-dev
開始編譯:
SDL2
gcc cube.c `pkg-config --cflags --libs sdl2`
SDL1
gcc cube.c `pkg-config --cflags --libs sdl`
範例輸出:
% 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