基於安卓的本地編譯環境

或許您有過這樣的需求,需要單獨的編譯一個c代碼在安卓機器上運行,但又不想去編寫Android.mk.對Android.mk情有獨鍾的您可以略過。因爲linux的工具實在是太多,相比Android toobox較爲完善, 有些工具能讓事半功倍,大大提高工作效率。最近在移植usb->wifi dangle,需要用到wireless_tools。但不巧的是toolbox中沒有,我們也只有在埋怨google的同時,自己動手豐衣足食。
首先從WirelessTools下載最新版工具,目前是wireless_tools.29。先看看DISTRIBUTIONS.txt和README大致瞭解下工具的用途。
編譯之前修改makefile,根據makefile的註釋只需修改如下選項:

## Compiler to use (modify this for cross compile).
CC = arm-linux-androideabi-gcc
## Other tools you need to modify for cross compile (static lib only).
AR = arm-linux-androideabi-ar
RANLIB = arm-linux-androideabi-ranlib

## Uncomment this to build tools using static version of the library.
## Mostly useful for embedded platforms without ldd, or to create
## a local version (non-root).
BUILD_STATIC = y

之前CC 和AR 以及RANLIB使用的都是,mtk6858 sdk的 編譯鏈。會莫名其妙的出現如下問題:
這裏寫圖片描述提示找不到stdio.h但是在交叉編譯工具目錄下肯定是有這個頭文件的。經過良久的琢磨與搜索終於在這裏發現了我想要的答案,Problems compiling object using arm-linux-androideabi-gcc。後來在mtk的sdk目錄找到make-standalone-toolchain.sh腳本,並執行make-standalone-toolchain.sh –platform=android-9 –install-dir=/tmp/my-toolchain卻終是錯誤,只好仔細閱讀了幫助文檔mtkv1.33/ndk/docs/text/STANDALONE-TOOLCHAIN.text,仍然一錯到底,心中不免有一萬隻草泥馬在奔騰。
後面只好下了一個原始的ndk,可以參考如下鏈接下載:

http://dl.google.com/android/ndk/android-ndk32-r10-windows-x86.zip
http://dl.google.com/android/ndk/android-ndk32-r10-windows-x86_64.zip
http://dl.google.com/android/ndk/android-ndk32-r10-darwin-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk32-r10-darwin-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk32-r10-linux-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk32-r10-linux-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-windows-x86.zip
http://dl.google.com/android/ndk/android-ndk64-r10-windows-x86_64.zip
http://dl.google.com/android/ndk/android-ndk64-r10-darwin-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-darwin-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-linux-x86.tar.bz2
http://dl.google.com/android/ndk/android-ndk64-r10-linux-x86_64.tar.bz2
http://dl.google.com/android/ndk/android-ndk-r10-cxx-stl-libs-with-debug-info.zip

在ndk跟目錄直接執行make-standalone-toolchain.sh –platform=android-9 –install-dir=~/work/my-toolchain 居然順利通過!此時已經是淚流滿面的我趕緊在wilelesstools makefile中改寫了編譯器路徑,直接make ,雖然arm-linux-androideabi/bin/ld: ifrename.o: in function main:ifrename.c(.text.startup+0x720): error: undefined reference to ‘getline’的錯誤,但對我來說已經無關緊要,因爲需要的其他工具已經編譯完畢!

發佈了95 篇原創文章 · 獲贊 23 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章