Game Development Reference
In-Depth Information
CROSS=arm-none-linux-gnueabi-
GCC=${CROSS}ld
# Uncomment for debugging
#echo "${GCC} $LD_FLAGS $LIB_PATHS $@ $LIBRARIES"
# Go!
${GCC} $LD_FLAGS $LIB_PATHS $@ $LIBRARIES
The
ald
script defines variables similar to those use used by the
agcc
script, which specify the
location of the required software components, plus some extra linker variables:
LIBRARIES
: This variable defines the basic libraries against which the final binary
should be linked. These are the C runtime (
-lc
), the Math library (
-lm
), and
libgcc.a
, which contains extra symbols required at link time. Note that the linker
will expand
-lc
to the name
libc.so
when reading the library from the file system.
•
LIB_PATHS
: Besides the library names defined in the previous step, the linker needs
to be able to find the libraries on the file system. Thus, you need to tell it where to
look. The
-Lpath1
, -
Lpath2
, and so on tell the compiler where to look for libraries.
Also,
-rpath
sets the runtime shared library search path. You need to define two
runtime search paths:
•
-rpath /system/lib
is the location of the runtime libraries in the device. It
must be defined so the program will be able to run properly in the device
itself.
•
-rpath ${SYS_ROOT}/lib
is the location of the same libraries on the desktop
system. It is required so the binary can compile properly.
•
•
LD_FLAGS
: This variable defines linker flags. Two flags are used by the script:
--dynamic-linker=/system/bin/linker
sets a program to use as the dynamic
linker. In this case,
/system/bin/linker
is the device.
•
•
-nostdlib
tells the linker not to use the standard libraries (C runtime, Math
library, and so on) defined by the toolchain, but instead use the libraries
defined by the user at link time.
And, finally, the command
${GCC} $LD_FLAGS $LIB_PATHS $@ $LIBRARIES
will expand to the
following:
$ arm-none-linux-gnueabi-ld --dynamic-linker=/system/bin/linker
-nostdlib -rpath /system/lib
-rpath /user/home/tmp/android/system/lib
-L/user/home/tmp/android/system /lib
-L/usr/lib/jvm/java-6-sun/jre/lib/i386
-L. [USER_ARGUMENTS] -lc -lm
/user/home/Desktop/android/arm-2008q3/lib/gcc/
arm-none-linux-gnueabi/4.3.2${LIBDIR}/libgcc.a
Note that
$@
in the script will expand to all arguments sent by the user in the command line.