Build Android Toolchain

   日期:2024-12-27    作者:b1247115 移动:http://3jjewl.riyuangf.com/mobile/quote/66606.html

Gen­er­at­ing or build­ing a set of stand­alone An­droid tool­chain is not an easy task. This ar­ti­cle sum­ma­rizes sev­eral is­sues I met when I tried to build binu­tils for ARM An­droid plat­form (). My setup is a Ubuntu 14.04 ma­chine () with all AOSP build­ing en­vi­ron­ment.

Build Android Toolchain

If you want a stand­alone tool­chain which can be used in your  ma­chine, you don't need to build from scratch. You can sim­ply gen­er­ate from An­droid NDK pack­age.

  • down­load and in­stall the lat­est NDK pack­age from https://​developer.​android.​com/​ndk/​downloads/​index.​html
  • change into  di­rec­tory
  • uti­lize  script to build a set of tool­chain

If you need a tool­chain run­ning on An­droid, things be­came a lit­tle com­pli­cated. For ex­am­ple, I want to run  or  on ARM An­droid. Be­cause we can­not get tool­chain build for ARM, let's try to build from scratch.

Be­cause An­droid main­tain their own tool­chain forked from GNU, we need first clone the source code from Google's repos­i­tory.

Be­sides the tool­chain source codes, we also need An­droid NDK pack­age.

We can get some build­ing in­for­ma­tion from tool­chain/build/README file. This tool­chain only sup­ports:

The  means which ma­chine can run the tool­chain, and the  means which tar­get ma­chine is this tool­chain used for. What we need here is and . That's why we need some extra mod­i­fi­ca­tion on the source code.

Firstly, we find the source code of binu­tils in . Sec­ondly, cre­ate a build script with con­fig­ure in it like mine:

Then, let's try it first with . How­ever, we may face these fol­low­ing er­rors.

To solve this issue, just com­ment this in­clude state­ment in  file.

com­ment the state­ments:

The so­lu­tion is same as pre­vi­ous issue, com­ment this header in  file.

com­ments the header state­ments:

The last error is:

The so­lu­tion is copy these two files from NDK sys­root to ld di­rec­tory. So, change our build­ing scripts as:

At last, we got:

Pay at­ten­tion the  and  flags in com­pil­ing and link­ing. Be­cause An­droid only sup­port po­si­tion in­de­pen­dent ex­e­cutable, we need to add flags to make PIE bi­na­ries. For Arch Linux users, you may meet  error. Just link  as  will solve this issue.


特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


举报收藏 0评论 0
0相关评论
相关最新动态
推荐最新动态
点击排行
{
网站首页  |  关于我们  |  联系方式  |  使用协议  |  隐私政策  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号