Game Development Reference
In-Depth Information
agcc -c main.c
ald -static -o a.out main.o
arm-none-linux-gnueabi-ld: cannot find -lc
The linker cannot find the C runtime
libc.so
, even though the path to the library is correct.
Remember that
ald
uses
-nostdlib
to bypass linking against standard libraries.
When compiling statically (using
-static
), you must remove
-nostdlib
from the loader. Thus, the
correct linking command should be as follows:
user@ubuntu:~/ch02.Project/native$ arm-none-linux-gnueabi-ld
--dynamic-linker=/system/bin/linker
-rpath /system/lib
-rpath /home/user/tmp/android/system/lib
-L/home/user/tmp/android/system/lib
-static -o a.out main.o -lc -lm
/home/user/mydroid/prebuilt/darwin-x86/toolchain/
arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1/libgcc.a
arm-none-linux-gnueabi-ld: warning: cannot find entry symbol _start;
defaulting to 000080e0
Now you can test
a.out
in the device:
$ make pushbin
$ adb shell
# ./a.out test
Main[0]=test
Hello World
Testing the Native Application
With the compiled library, you can test the phone application and see if the library is loaded by JNI.
From the command line, run the
make
command:
$ make lib
It will compile the library and also copy it to the assets folder in the Java project, so it can be
installed when the application runs. Don't forget to refresh the project folder (press F5 on the main
folder), so the IDE will pack it before running it.
Now let's create a run configuration and start the application. Here is how:
1.
Select Run
Run Configurations from the main menu.
2.
In the Run Configurations dialog box, right-click Android Application in the
left tree and choose New.
Enter a configuration name (
ch02
) and select a project (
ch02.Project
), as
shown in Figure 2-6. Then click Run.
3.