安装SDL2.0

来源:互联网 发布:淘宝店怎么加入淘宝客 编辑:程序博客网 时间:2024/06/16 19:47

在ubuntu上本来已经装好了SDL1.2,如何安装SDL2.0

SDL1.2和SDL2.0可以共存

一般在头文件在/usr/include,其他的库文件如果不确定可以用locate命令查看。
如:locate -b libSDL*.a查看静态库文件。

然后到SDL官网下载SDL2.0的源码,开始安装:
./configure
make
make install
安装好后,
头文件在/usr/local/include
库文件在/usr/local/lib


写个小程序测试一下是否安装好了:
#include<SDL2/SDL.h>int main(int argc,char*args[]){SDL_Init(SDL_INIT_EVERYTHING);SDL_Quit();return 0;}


gcc test.c -lSDL2



出现一个编译错误:
上一次编译ffmpeg的时候也出现过类似的错误,应该是编译库的链接问题;
查看SDL2的pkg文档,发现正确的链接方式为:
gcc test.c -lSDL2   -Wl,--no-undefined -lm -ldl -lpthread -lrt
马上没错了:)

14:37:27: Running build steps for project SDL_Test...14:37:27: Configuration unchanged, skipping qmake step.14:37:27: Starting: "/usr/bin/make" -wmake: Entering directory `/home/exbot/Desktop/Qt/SDL_Test-build-desktop-Qt_4_8_1_in_PATH__System__Release'gcc -c -pipe -O2 -Wall -W -DQT_WEBKIT -I/usr/share/qt4/mkspecs/linux-g++ -I../../SDL/SDL_Test -I../../SDL/SDL_Test -I/usr/local/include -I. -o main.o ../../SDL/SDL_Test/main.c../../SDL/SDL_Test/main.c: In function 'main':../../SDL/SDL_Test/main.c:12:14: warning: unused parameter 'argc' [-Wunused-parameter]../../SDL/SDL_Test/main.c:12:24: warning: unused parameter 'args' [-Wunused-parameter]g++ -Wl,-O1 -o SDL_Test main.o     -L./usr/local/lib/ -lSDL2 -lm -lbz2 -lz -pthread -lrt /usr/local/lib/libSDL2.a(SDL_dynapi.o): In function `get_sdlapi_entry':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/dynapi/SDL_dynapi.c:237: undefined reference to `dlopen'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/dynapi/SDL_dynapi.c:240: undefined reference to `dlsym'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/dynapi/SDL_dynapi.c:242: undefined reference to `dlclose'/usr/local/lib/libSDL2.a(SDL_sysloadso.o): In function `SDL_LoadObject_REAL':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/loadso/dlopen/SDL_sysloadso.c:36: undefined reference to `dlopen'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/loadso/dlopen/SDL_sysloadso.c:37: undefined reference to `dlerror'/usr/local/lib/libSDL2.a(SDL_sysloadso.o): In function `SDL_LoadFunction_REAL':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/loadso/dlopen/SDL_sysloadso.c:47: undefined reference to `dlsym'make: Leaving directory `/home/exbot/Desktop/Qt/SDL_Test-build-desktop-Qt_4_8_1_in_PATH__System__Release'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/loadso/dlopen/SDL_sysloadso.c:54: undefined reference to `dlsym'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/loadso/dlopen/SDL_sysloadso.c:58: undefined reference to `dlerror'/usr/local/lib/libSDL2.a(SDL_sysloadso.o): In function `SDL_UnloadObject_REAL':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/loadso/dlopen/SDL_sysloadso.c:68: undefined reference to `dlclose'/usr/local/lib/libSDL2.a(SDL_systhread.o): In function `SDL_SYS_CreateThread':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/thread/pthread/SDL_systhread.c:95: undefined reference to `dlsym'/usr/local/lib/libSDL2.a(SDL_x11opengl.o): In function `X11_GL_LoadLibrary':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:164: undefined reference to `dlopen'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:187: undefined reference to `dlsym'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:190: undefined reference to `dlsym'/usr/local/lib/libSDL2.a(SDL_x11opengl.o): In function `X11_GL_GetProcAddress':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:263: undefined reference to `dlsym'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:263: undefined reference to `dlsym'/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:263: undefined reference to `dlsym'/usr/local/lib/libSDL2.a(SDL_x11opengl.o):/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:263: more undefined references to `dlsym' follow/usr/local/lib/libSDL2.a(SDL_x11opengl.o): In function `X11_GL_LoadLibrary':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:167: undefined reference to `dlerror'/usr/local/lib/libSDL2.a(SDL_x11opengl.o): In function `X11_GL_GetProcAddress':/home/exbot/Desktop/SDL/SDL2-2.0.4/src/video/x11/SDL_x11opengl.c:263: undefined reference to `dlsym'collect2: ld returned 1 exit statusmake: *** [SDL_Test] Error 114:37:27: The process "/usr/bin/make" exited with code 2.Error while building project SDL_Test (target: Desktop)When executing build step 'Make'









0 0