將 SDL整合至Android平台

來源:互聯網
上載者:User


路上有很多文章在講解如何將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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.