問題:在使用NDK移植流媒體SDK至Android平臺下時,因爲在本身的工程下,不能使用Android.mk與Application.mk,直接指定android-ndk-r8b下的交叉編譯工具進行編譯,結果提示找不到STL相關頭文件等一大堆錯誤,從網上下載了其餘版本的NDK工具鏈也不行,把STL頭文件絕對路徑加上以及加入了全部STL相關編譯選項後仍是不能編譯經過。後來仔細閱讀官網資料,獲得一個信息——Android NDK提供了腳原本剝離出單獨的toolchain,腳本的名字叫make-standalone-toolchain.sh,其製做出來的工具鏈不依賴NDK下的環境變量,且支持STL,運用製做出的工具鏈編譯工程代碼,問題獲得解決,下邊將其製做的具體步驟。html
1. 下載Android NDKlinux
http://developer.android.com/sdk/ndk/index.htmlandroid
我用的是android-ndk-r8b-linux-x86.tar.bz2c++
wget http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86.binexpress
2. 提取toolchainide
以參考文檔docs/STANDALONE-TOOLCHAIN.html工具
在linux系統中解壓NDK,假設解壓到/opt;ui
# cd /opt/android-ndk-r8b/google
# build/tools/make-standalone-toolchain.sh --platform=android-14idea
# cd android-ndk-r10e
#./build/tools/make-standalone-toolchain.sh --platform=android-14
--toolchain=arm-linux-androideabi-4.9
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.6
Copying prebuilt binaries...
Copying sysroot headers and libraries...
Copying libstdc++ headers and libraries...
Creating package file: /tmp/ndk-caiwang213/arm-linux-androideabi-4.6.tar.bz2
Cleaning up...
Done.
有一些警告沒有關係,最終獲得的是一個壓縮包/tmp/ndk-caiwang213/
arm-linux-androideabi-4.6.tar.bz2
3. 安裝arm-linux-androideabi-4.6.tar.bz2工具鏈
# tar jxvf arm-linux-androideabi-4.6.tar.bz2 -C /usr/local
4. 將工具鏈環境變量加入到/etc/profile文件中
# vi /etc/profile
在最下邊加入一行export PATH=$PATH:/usr/local/standalone-
toolchain-androideabi-4.6/bin
# source /etc/profile
5. Makefile變量設定
CROSS_COMPILER = arm-linux-androideabi-
CFLAGS += -O2 -static
STANDALONE_PATH=/usr/local/standalone-toolchain-androideabi-4.6
INCLUDES += -I$(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/
INCLUDES += -I$(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi
6.make編譯工程,提示
/usr/local/standalone-toolchain-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/as: /usr/lib/libz.so.1: no version information available (required by /usr/local/standalone-toolchain-androideabi-4.6/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/bin/as)
但編譯能夠經過,編譯出來的庫能夠在Android下調用成功