关闭

將 SDL整合至Android平台

标签: androidcompilerincludemakefilebuildheader
4209人阅读 评论(0) 收藏 举报
分类:

網 路上有很多文章在講解如何將SDL整合到Android的平台上,我自己也試著動手做看看,順便將一些步驟及心得整理起來。

以下是這次我所用到的開發環境。

- Cygwin
- Android NDK:android-ndk-r4b-windows
- SDL
:1.2.14


《Step 1》
將SDL中的Makefile.minimal修改如下 (紅體字) :

# Makefile to build the SDL library

PREBUILT = /android-ndk-r4b/build/prebuilt/windows/arm-eabi-4.4.0

INCLUDE = -I./include -I/android-ndk-r4b/build/platforms/android-8/arch-arm/usr/include
CFLAGS  = -g -O2 $(INCLUDE)
CC  = $(PREBUILT)/bin/arm-eabi-gcc
AR  = $(PREBUILT)/bin/arm-eabi-ar
RANLIB  = $(PREBUILT)/bin/arm-eabi-ranlib

CONFIG_H = include/SDL_config.h
TARGET  = libSDL.a
SOURCES = /
    src/*.c /
    src/audio/*.c /
    src/cdrom/*.c /
    src/cpuinfo/*.c /
    src/events/*.c /
    src/file/*.c /
    src/joystick/*.c /
    src/stdlib/*.c /
    src/thread/*.c /
    src/timer/*.c /
    src/video/*.c /
    src/audio/dsp/*.c /
    src/audio/dma/*.c /
    src/video/fbcon/*.c /
    src/joystick/dummy/*.c /
    src/cdrom/dummy/*.c /
    src/thread/generic/*.c /
    src/timer/unix/*.c /
    src/loadso/dummy/*.c /

OBJECTS = $(shell echo $(SOURCES) | sed -e 's,/.c,/.o,g')

all: $(TARGET)

$(TARGET): $(CONFIG_H) $(OBJECTS)
    $(AR) crv $@ $^
    $(RANLIB) $@

$(CONFIG_H):
    cp $(CONFIG_H).default $(CONFIG_H)

clean:
  rm -f $(TARGET) $(OBJECTS)



《Step 2》
修改 ./include/SDL_config_minimal.h (紅體字) :

#ifndef _SDL_config_minimal_h
#define _SDL_config_minimal_h

#include "SDL_platform.h"

/* This is the minimal configuration that can be used to build SDL */

#include <stdarg.h>

typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef unsigned int size_t;
typedef unsigned long uintptr_t;

#define SDL_AUDIO_DRIVER_OSS    1

#define SDL_CDROM_DISABLED  1

#define SDL_JOYSTICK_DISABLED   1

#define SDL_LOADSO_DISABLED 1

#define SDL_THREADS_DISABLED    1

#define SDL_TIMER_UNIX  1

#define SDL_VIDEO_DRIVER_FBCON  1

#define HAVE_STDIO_H 1

#endif /* _SDL_config_minimal_h */



《Step 3》
由於Android的framebuffer設 備是 /dev/graphics/fb0 (Linux是 /dev/fb0),所以我們需要修改 ./src/video/fbcon/SDL_fbvideo.c。將檔案中所有的/dev/fb0全都置換成/dev/graphics/fb0


《Step 4》
開始編譯 libSDL.a,在 Cygwin下進入SDL的根目錄,輸入

make -f Makefile.minimal


《Step 4.1》

make 的過程中會遇到一些compile error,我們一步步來解決它們。首先,compiler會告訴我們某些變數已經 (在SDL_config_minimal.h) 重覆定義了:

/android-ndk-r4b/build/platforms/android-8/arch-arm/usr/include/stdint.h:53: error: redefinition of typedef 'int8_t'
./include/SDL_config_minimal.h:32: note: previous declaration of 'int8_t' was here


解決 的辦法是將SDL_config_minimal.h中重覆定義的部分mark起來 (紅體字):

//typedef signed char int8_t;
//typedef unsigned char uint8_t;
//typedef signed short int16_t;
//typedef unsigned short uint16_t;
//typedef signed int int32_t;
//typedef unsigned int uint32_t;
//typedef unsigned int size_t;
//typedef unsigned long uintptr_t;


《Step 4.2》
接 著,compiler認為SDL_dummy_enum的size不合法:

./include/SDL_stdinc.h:151: error: size of array 'SDL_dummy_enum' is negative

在 這邊,我將SDL_stdinc.h的151行mark起來 (紅體字):

//SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));

《Step 4.3》
最後會遇到的error是找不到soundcard.h:

src/audio/dsp/SDL_dspaudio.c:44:27: error: sys/soundcard.h: No such file or directory

因 為sys/soundcard.h指的是/cygwin/usr/include下的header檔,所以我們要回到Makefile.minimal中 的INCLUDE,將該路徑告訴compiler (紅體字):

INCLUDE = -I./include -I/android-ndk-r4b/build/platforms/android-8/arch-arm/usr/include -I/usr/include

修 改完之後再重新make。



《Step 5》
成功,在SDL的 根目錄下產生libSDL.a

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:135107次
    • 积分:1751
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:118篇
    • 译文:1篇
    • 评论:11条
    最新评论