How to run a dynamically compiled program in the Android system

Source: Internet
Author: User

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 ~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.