使用Android NDK中的独立toolchain来开发C/C++程序

taiyuanwuyin 2011-10-26

从网上可以找到一些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机器上的目录。

相关推荐

cherayliu / 0评论 2020-06-13