Compiling C + + executables in the arm Android environment

Source: Internet
Author: User

A C + + executable that compiles an arm environment is primarily compiled with a cross-compiler. The compilation process itself is very similar.

1. To install the cross compiler, the cross-compiler installation method is roughly the following:

The A.debian/ubuntu system can be installed directly into the command:

sudo Install g++-arm-linux-gnueabihf    sudoinstall g++-8- ARM-LINUX-GNUEABIHF        #这种方式还可以指定版本

B. Direct download of the cross-compiler binary files, ARM official website, this site download speed is relatively slow, Baidu keyword Gcc-arm-none-eabi to find the domestic, download decompression, Add the extracted directory to the PATH environment variable or copy the extracted files to the/usr/bin directory

C. Download Android NDK,NDK with a cross-compilation tool chain for Android, which can be found in the prebuilt directory after download

D. Download the GCC source code, manually compile the installation

The above several methods in addition to manual compilation may encounter a variety of dependency problems, the rest is relatively simple, I just use the Ubuntu 18.04 system, using a method installed.

2. Compile the code with the cross compiler, and now write a very old program and compile it with a cross compiler:

#include <iostream>usingnamespace  std; int Main () {    "Hello World, from Android C + +"  << Endl;     return 0 ;}

To perform a command compilation:

arm-linux-gnueabihf-g++-8  -static  helloworld.cpp     # Be sure to add -static statically linked options, Otherwise, the compiled a.out can't execute.

3. Connect your Android device to your computer and then use the steps below to re-mount Android as a writable

adb root           # This command requires that the phone has        rootadb remount"mount-o rw,remount/system"    # RW Indicates mount as readable/writable Read/write

Mount it later use the ADB shell to sign in to the Android shell environment and create a folder "HelloWorld" that we use for this test

Then use the ADB command to push the file to the Android device.

ADB push./a . Out/data/helloworld

4. Log in to the Android shell environment again, assign permissions to the A.out file (if you already have the executable permission you can not assign permissions again), and then execute:

adb shell                 /data/HelloWorld      777 A.out          #赋权限为777. /a. Out                  #执行a.  out

As you can see, the "Hello World, from Android C + +" is finally successfully exported.

Compiling C + + executables in the arm Android environment

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.