android framework添加對C++的支持

最近在將C++ STL寫的模塊移植到frameworks/av/media中,遇到了很多編譯方面的問題,通過努力,順利編譯通過,下面將過程記錄一下,以便以後參考:

下面的方法在android-5.1.1_r9上測試過,編譯選項aosp_x86。

1. android默認不支持C++ STL,雖然在NDK已經可以支持了。

    如果需要支持STL,則需要手動添加一些靜態庫和鏈接庫,從而達到可以支持STL的目的。


2. STL模塊函數找不到,鏈接失敗

stdc++/include/bits/stl_list.h:466: error: undefined reference to '__cxa_end_catch
stdc++/include/bits/stl_list.h:469: error: undefined reference to '__cxa_rethrow'
nal_baseD1Ev+0x0): error: undefined reference to '__gxx_personality_v0'
這是缺libsupc++.a


Android.mk
LOCAL_SHARED_LIBRARIES += \
libstlport\


prebuilt_stdcxx_PATH := prebuilts/ndk/current/sources/cxx-stl


LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(TOP)/frameworks/av/media/libstagefright \
bionic \
external/stlport/stlport\

LOCAL_LDFLAGS :=  -L$(prebuilt_stdcxx_PATH)/gnu-libstdc++/libs/$(TARGET_CPU_ABI) -lsupc++ -L$(prebuilt_stdcxx_PATH)/gabi++/libs/$(TARGET_CPU_ABI) -lstdc++ -lgabi++
LOCAL_LDLIBS := -lstdc++ $(prebuilt_stdcxx_PATH)/gnu-libstdc++/libs/armeabi/libsupc++.a


LOCAL_CFLAGS    := -Werror -fexceptions \
-O0 -g -Wno-unused-parameter\
-Wno-error=unused-variable\
-Wno-sign-compare -Wno-switch   \
                -std=gnu++11

3. 由於android的原生代碼裏沒有對list的支持,因此,需要將list的頭文件替換掉,最好是替換爲vector,用vector的方法來編譯

4. android 的ABuffer是在namespace android中定義的,因此,需要將引用該類的文件包含在namespace android中。

5. when you meet an error which is about "undefined reference to '__gxx_personality_v0'", the only one problem maybe that there are many stdc++ reference. You need delete all the other "stdc++" except the last one. Just as in LOCAL_LDFLAGS above.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章