Problem Description:
I use mini6410 to develop a SQLite database program, under the MINI6410 Linux system has been able to run successfully. Because Android is also using the Linux kernel, I take it for granted that the same method of porting the program to MINI6410 's Android system can run successfully, But when I ran the program, I was prompted that I couldn't find the executable file (Xlisten-arm is a cross-compiled executable):
/#./xlisten-arm
/system/bin/sh:./xlisten-arm:not found
1. Explore:
The web search was initially thought to be a result of the incomplete library file, so the dynamic link library needed to view the executable file Xlisten-arm:
Execute statement:
- # arm-linux-readelf-a./xlisten-arm | grep "Shared"
- 0x00000001 (NEEDED) Shared library: [libsqlite3.so.0]
- 0x00000001 (NEEDED) Shared library: [libm.so.6]
- 0x00000001 (NEEDED) Shared library: [Libcrypt.so.1]
- 0x00000001 (NEEDED) Shared library: [libpthread.so.0]
- 0x00000001 (NEEDED) Shared library: [Libdl.so.2]
- 0x00000001 (NEEDED) Shared library: [libc.so.6]
Know the required dynamic link library, to the Android file system to follow the write library file, in the directory/system/lib, really missing the corresponding library file, so that found the root of my problem, in the copy of the corresponding library files in order to preserve the original properties, but also deliberately used
- #cp-a filename dir
Who knows to add these libraries are still useless!
It seems not only that the library file is missing, and generally, if the problem is caused by the lack of a library file, the terminal will prompt us to link a library file without finding the library file.
2. Correct solution:
Choose static compilation When compiling the program, that is, using the option-static
I'm modifying the Cflag variable in the makefile file
CFLAGS =-wall
Switch
CFLAGS =-wall-static
However, there is a problem at this point:
Undefined reference to ' pthread_mutex_* '
Undefined reference to ' dl* '
The prompt does not define these functions, so you add both library files to the included library file
In makefile, modify the Libs variable;
LIBS =-lsqlite3-lm-lcrypt
Switch
LIBS =-LSQLITE3-LM-LCRYPT-LPTHREAD-LDL
Then cross-compile and succeed!
Compiled executable file is relatively large, because things statically compiled, I have more than 2M,
To the andriod system of the Development Board,
Modify Permissions:
#chmod 777 Xlisten-arm
Perform:
/#./xlisten-arm
The ok! can be executed correctly!
How to run a C language program in Android