安装SDL2.0

在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" -w
make: 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 status
make: *** [SDL_Test] Error 1
14:37:27: The process "/usr/bin/make" exited with code 2.
Error while building project SDL_Test (target: Desktop)
When executing build step 'Make'









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值