Game Development Reference
In-Depth Information
Introduction
This chapter explains how to port existing popular C/C++ libraries to Android using Android
NDK. These libraries are widely used to implement feature-rich applications with graphics,
sounds, and physical simulations entirely in C++. There is not much fun in simply compiling
libraries. So, the parts related to FreeImage, FreeType, and Box2D provide minimal samples to
demonstrate the functionality of each library. Audio and networking libraries are discussed in
greater detail in the subsequent chapters. We will show you how to compile libraries and,
of course, give some short samples and hints on how to start using them.
Typical caveats for porting libraries across different processors and operating systems are
memory access (structure alignment/padding), byte-order (endianness), calling conventions,
and loating-point issues. All the libraries described below address these issues quite well,
and even if some of them do not oficially support Android NDK, ixing this is just a matter of
a few compiler switches.
To build any of the mentioned libraries, we need to create makeile for the Windows version
and a pair of the Android.mk and the Application.mk iles for Android NDK. The source
iles of the library are compiled to object iles. A collection of object iles is combined into
an archive, which is also called a static library. Later, this static library can be passed as
an input to the linker. We start with the Windows version because the Android.mk and
Application.mk iles are built on top of standard makeiles.
Compiling the native static libraries for
Windows
To build the Windows version of libraries, we need a C++ compiler. We use MinGW with the
GCC toolchain described in Chapter 1 , Establishing a Build Environment . For each library,
we have a collection of source-code iles, and we need to get the static library, a ile with the
.a extension.
Getting ready
Let us assume the src directory contains the source code of a library we need to build
for Android.
How to do it...
1. Let us start with writing a makeile:
CFLAGS = -I src
 
Search WWH ::




Custom Search