linux 下如何编译使用SDL的工程
首先看一下SDL的头文件在哪,一般在/usr/include/SDL里面,跟你具体的安装路径有关
在我的bash中输入 find /usr/include -name SDL*
输出如下:
/usr/include/SDL
/usr/include/SDL/SDL_gfxPrimitives.h
/usr/include/SDL/SDL_platform.h
/usr/include/SDL/SDL_video.h
/usr/include/SDL/SDL_gfxPrimitives_font.h
/usr/include/SDL/SDL_stdinc.h
/usr/include/SDL/SDL_quit.h
/usr/include/SDL/SDL_keysym.h
/usr/include/SDL/SDL_mixer.h
/usr/include/SDL/SDL_endian.h
/usr/include/SDL/SDL_joystick.h
/usr/include/SDL/SDL_version.h
/usr/include/SDL/SDL_mutex.h
/usr/include/SDL/SDL_thread.h
/usr/include/SDL/SDL.h
/usr/include/SDL/SDL_framerate.h
/usr/include/SDL/SDL_events.h
/usr/include/SDL/SDL_image.h
/usr/include/SDL/SDL_loadso.h
/usr/include/SDL/SDL_net.h
/usr/include/SDL/SDL_rwops.h
/usr/include/SDL/SDL_error.h
/usr/include/SDL/SDL_active.h
/usr/include/SDL/SDL_keyboard.h
/usr/include/SDL/SDL_rotozoom.h
/usr/include/SDL/SDL_name.h
/usr/include/SDL/SDL_syswm.h
/usr/include/SDL/SDL_cpuinfo.h
/usr/include/SDL/SDL_opengl.h
/usr/include/SDL/SDL_timer.h
/usr/include/SDL/SDL_types.h
/usr/include/SDL/SDL_cdrom.h
/usr/include/SDL/SDL_mouse.h
/usr/include/SDL/SDL_imageFilter.h
/usr/include/SDL/SDL_audio.h
/usr/include/SDL/SDL_byteorder.h
/usr/include/SDL/SDL_config.h
/usr/include/SDL/SDL_getenv.h
/usr/include/SDL/SDL_main.h
我们再看一下so文件的位置,输入: find /usr/lib -name libSDL*
/usr/lib/libSDL.so
/usr/lib/libSDLmain.a
/usr/lib/libSDL_console.so
/usr/lib/libSDL_net-1.2.so.0.0.7
/usr/lib/libSDL-1.2.so.0.11.1
/usr/lib/libSDL_gfx.so
/usr/lib/libSDL_net.la
/usr/lib/libSDL_mixer-1.2.so.0
/usr/lib/libSDL_net-1.2.so.0
/usr/lib/libSDL_image-1.2.so.0
/usr/lib/libSDL_gfx.la
/usr/lib/libSDL_mixer.la
/usr/lib/libSDL.a
/usr/lib/libSDL_image-1.2.so.0.1.5
/usr/lib/libSDL.la
/usr/lib/libSDL_net.so
/usr/lib/libSDL-1.2.so.0
/usr/lib/libSDL_mixer.a
/usr/lib/libSDL_console.a
/usr/lib/libSDL_gfx.so.4
/usr/lib/libSDL_image.so
/usr/lib/libSDL_mixer-1.2.so.0.2.6
/usr/lib/libSDL_image.la
/usr/lib/libSDL_gfx.a
/usr/lib/libSDL_image.a
/usr/lib/libSDL_console.so.1
/usr/lib/libSDL_console.so.1.3
/usr/lib/libSDL_net.a
/usr/lib/libSDL_mixer.so
/usr/lib/libSDL_gfx.so.4.9.0
于是,我们编译的时候,只需要加上:
-I/usr/include/SDL -L/usr/libSDL
就可以了
以上参数可以用如下指令生成:
`sdl-config --cflags`
`sdl-config --libs`
sdl-config是一个shell脚本
可以通过which sdl-config找到其位置,然后查看其内容
#!/bin/sh
prefix=/usr
exec_prefix=${prefix}
exec_prefix_set=no
libdir=${exec_prefix}/lib
#usage="/
#Usage: sdl-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"
usage="/
Usage: sdl-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]"
if test $# -eq 0; then
echo "${usage}" 1>&2
exit 1
fi
while test $# -gt 0; do
case "$1" in
-*=*) ptarg=`echo "$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) ptarg= ;;
esac
case $1 in
--prefix=*)
prefix=$optarg
if test $exec_prefix_set = no ; then
exec_prefix=$optarg
fi
;;
--prefix)
echo $prefix
;;
--exec-prefix=*)
exec_prefix=$optarg
exec_prefix_set=yes
;;
--exec-prefix)
echo $exec_prefix
;;
--version)
echo 1.2.12
;;
--cflags)
echo -I${prefix}/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
;;
--libs)
echo -L${exec_prefix}/lib -lSDL
;;
--static-libs)
# --libs|--static-libs)
echo -L${exec_prefix}/lib -lSDL -lpthread
;;
*)
echo "${usage}" 1>&2
exit 1
;;
esac
shift
done
当然如果还用到其它lib如libSDK_image.so, 则还是加上 -L/usr/lib/SDL_image
下面是一个Makefile:
CC = g++
LD = g++
CFLAGS = `sdl-config --cflags`
LDFLAGS = `sdl-config --libs` -lSDL_image
RM = /bin/rm -f
OBJS = mouse_tile.o
PROG = mouse_tile
VERS = 0.1.0
.PHONY: clean distclean
all: $(PROG)
$(PROG): $(OBJS)
$(LD) $(LDFLAGS) -s -o $(PROG) $(OBJS)
mouse_tile.o: mouse_tile.cpp
$(CC) $(CFLAGS) -O2 -c mouse_tile.cpp
clean:
$(RM) *~ $(OBJS) $(PROG)
.PHONY: clean
更多推荐
所有评论(0)