Generating or building a set of standalone Android toolchain is not an easy task. This article summarizes several issues I met when I tried to build binutils for ARM Android platform (). My setup is a Ubuntu 14.04 machine () with all AOSP building environment.
If you want a standalone toolchain which can be used in your machine, you don't need to build from scratch. You can simply generate from Android NDK package.
- download and install the latest NDK package from https://developer.android.com/ndk/downloads/index.html
- change into directory
- utilize script to build a set of toolchain
If you need a toolchain running on Android, things became a little complicated. For example, I want to run or on ARM Android. Because we cannot get toolchain build for ARM, let's try to build from scratch.
Because Android maintain their own toolchain forked from GNU, we need first clone the source code from Google's repository.
Besides the toolchain source codes, we also need Android NDK package.
We can get some building information from toolchain/build/README file. This toolchain only supports:
The means which machine can run the toolchain, and the means which target machine is this toolchain used for. What we need here is and . That's why we need some extra modification on the source code.
Firstly, we find the source code of binutils in . Secondly, create a build script with configure in it like mine:
Then, let's try it first with . However, we may face these following errors.
To solve this issue, just comment this include statement in file.
comment the statements:
The solution is same as previous issue, comment this header in file.
comments the header statements:
The last error is:
The solution is copy these two files from NDK sysroot to ld directory. So, change our building scripts as:
At last, we got:
Pay attention the and flags in compiling and linking. Because Android only support position independent executable, we need to add flags to make PIE binaries. For Arch Linux users, you may meet error. Just link as will solve this issue.