最近在將C++ STL寫的模塊移植到frameworks/av/media中,遇到了很多編譯方面的問題,通過努力,順利編譯通過,下面將過程記錄一下,以便以後參考:
下面的方法在android-5.1.1_r9上測試過,編譯選項aosp_x86。
1. android默認不支持C++ STL,雖然在NDK已經可以支持了。
如果需要支持STL,則需要手動添加一些靜態庫和鏈接庫,從而達到可以支持STL的目的。
2. STL模塊函數找不到,鏈接失敗
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
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.