How to run a dynamically compiled program in the Android system
The android system uses the linux kernel at the underlying level, but it is different from linux in the file system. We can use the ADB tool provided by Google to access the linux Command terminal of the android system. However, we cannot execute applications that are dynamically compiled through the arm-linux-gcc and other Cross compilers on the PC, such as the following commands:
arm-linux-gcc mc.c -o mc
Then, use adb push to copy the executable program to the android system/data/local, and then change the permission:
adb shell chmod 777 /data/local/mc
Finally, run the application in the/data/local directory:
./mc
The following message is displayed:
1 | root @ android:/data/local #./mc
/System/bin/sh:./mc: No such file or directory
This indicates that the required link library cannot be found in the system, and can be executed smoothly in the arm-linux system. This indicates that the dependency libraries in linux are missing from the android system. Of course, static compilation with the-static option can solve the problem, but the static compiled files are usually dozens of times larger than the dynamically compiled files, A simple makefile may be more than five hundred KB. This is not cost-effective for a long time. We can find these libraries in the linux File System. The method is as follows:
First, find the file system compressed package file_system.tar.gz in the linux source code.
Extract
tar xzvf file_system.tar.gz
Copy all the content in lib to the/lib directory of android:
adb push lib /lib
At this time, the library files in linux can be found in android. At this time, go back to the/data/local directory of the android system and execute the static compilation file again.
In addition, in linux, We can configure environment variables or put the mc executable file in the/bin directory, so that we can execute this command in any path. Is there any similar operation in the android system? Of course we can. We can put the executable file mc in the/system/bin directory. Is it very convenient?
If you have any questions, please leave a message below for discussion ~~