Game Development Reference
In-Depth Information
The following lines give a clue to the source of the problem:
stat64("/system/lib/libch02.so", 0xbef9ea58) = -1 ENOENT (No such file or directory)
stat64("/lib/libch02.so", 0xbef9ea58) = -1 ENOENT (No such file or directory)
The linker first tries to open the library from the device /system/lib folder. This is a read-only file
system, and user-defined libraries cannot be saved there. Next, the linker searches the /lib folder, which
doesn't exist, thus the link fails. The linker is not searching in the current directory—that is the problem!
The good news is that this will not prevent the library from loading within the Java application, as
long as there are no missing symbols.
If you run the same sequence in a version 1.0 R2 of the SDK, you will see that the second line
becomes the following:
stat64("./libch02.so", 0xbef9ea58) = 0 OK
Thus, the program runs successfully.
Note It is hard to say what has changed from version 1.0 to 1.5 in the file bionic/linker/linker.c , as Google
provides no support in this matter. I can only speculate, but my guess is that either the developers forgot to search
in the current folder or some new compilation option can be used to tell the linker where to search.
Compiling Statically
Finally, if you wish to write a command-line tool to run in the device, you must do so statically. Consider
the simple program in Listing 2-10 to print the command-line arguments to stdout .
Listing 2-10. Simple Command-Line Program
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
for ( i = 0 ; i < argc ; i++ ) {
printf("Main argv[%d]=%s\n", i, argv[i]);
}
printf("Hello World\n");
exit( 0);
}
If you compile the program with -static using the helper scripts, you get the following error:
Search WWH ::




Custom Search