歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

使用Android NDK中的獨立toolchain來開發C/C++程序

從網上可以找到一些ARM toolchain,但是由於Android系統使用的不是glibc而是Bionic libc。因此只能使用靜態編譯程序。

其實Android的NDK自帶了toolchain,但是不能直接使用NDK目錄內的toolchain,否則會出現找不到crtbegin_dynamic.o文件。

即使用-L指定目錄或者直接放到gcc命令行也還是提示該文件找不到。(參考最後附上的鏈接)。

其實Android NDK提供了腳本來剝離出單獨的toolchain,腳本的名字叫make-standalone-toolchain.sh


1. 下載Android NDK

http://developer.android.com/sdk/ndk/index.html

我用的是android-ndk-r6b


2. 提取toolchain


可以參考文檔docs/STANDALONE-TOOLCHAIN.html

在linux系統中解壓NDK,假設解壓到/opt;

cd /opt/android-ndk-r6b/

build/tools/make-standalone-toolchain.sh --platform=android-8


expr: warning: unportable BRE: `^\\([^\\-].*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\(--[^=]*\\)=.*$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^--[^=]*=\\(.*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
Auto-config: --toolchain=arm-linux-androideabi-4.4.3
Copying prebuilt binaries...
Copying sysroot headers and libraries...
Copying libstdc++ headers and libraries...
expr: warning: unportable BRE: `^\\([^\\-].*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\(--[^=]*\\)=.*$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\(--.*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\([^\\-].*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\([^\\-].*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\([^\\-].*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^\\(--[^=]*\\)=.*$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
expr: warning: unportable BRE: `^--[^=]*=\\(.*\\)$': using `^' as the first character
of the basic regular expression is not portable; it is being ignored
Creating package file: /tmp/ndk-hansel/arm-linux-androideabi-4.4.3.tar.bz2
Cleaning up...
Done.


有一些警告沒有關系,最終得到的是一個壓縮包 /tmp/ndk-hansel/arm-linux-androideabi-4.4.3.tar.bz2

注意:這個是我的Linux機器上的目錄。

Copyright © Linux教程網 All Rights Reserved