1 在需要调用模板库的文件前包含头文件:
#include <iostream>
#include <vector>
此时编译可能不过,需要在android.mk文件内添加:
LOCAL_C_INCLUDES := /home/administrator/android-ndk-r5b/sources/cxx-stl/stlport/stlport (ndk安装路径下的stl库)
2 在 mk 文件前加入:
APP_STL := stlprot_static (模板库以静态库的方式添加)
....
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog \
/home/administrator/android-ndk-r5b/sources/cxx-stl/stlport/libs/armeabi/libstlport_static.a
我的Android.mk文件中的内容为:
LOCAL_PATH := $(call my-dir)LOCAL_C_INCLUDES += external/stlport/stlportLOCAL_C_INCLUDES += bionicLOCAL_C_INCLUDES += bionic/libstdc++/includeLOCAL_SHARED_LIBRARIES := libstlportGXPM_LIB_DIR := ../../../common/GoxceedPMinclude $(CLEAR_VARS) #$(GXPM_LIB_DIR)/minidb/minilzo/minilzo.c \GXPM_SRC_FILES := \ $(GXPM_LIB_DIR)/zlib/adler32.c \ $(GXPM_LIB_DIR)/zlib/compress.c \ $(GXPM_LIB_DIR)/zlib/crc32.c \ $(GXPM_LIB_DIR)/zlib/deflate.c \ $(GXPM_LIB_DIR)/zlib/gzio.c \ $(GXPM_LIB_DIR)/zlib/inffast.c \ $(GXPM_LIB_DIR)/zlib/inflate.c \ $(GXPM_LIB_DIR)/zlib/inftrees.c \ $(GXPM_LIB_DIR)/zlib/trees.c \ $(GXPM_LIB_DIR)/zlib/uncompr.c \ $(GXPM_LIB_DIR)/zlib/zutil.c \ $(GXPM_LIB_DIR)/lz4/lz4.c \ $(GXPM_LIB_DIR)/lz4/lz4frame.c \ $(GXPM_LIB_DIR)/lz4/lz4hc.c \ $(GXPM_LIB_DIR)/lz4/xxhash.c \ $(GXPM_LIB_DIR)/minilzo/minilzo.c \ $(GXPM_LIB_DIR)/minidb/bitmap.c \ $(GXPM_LIB_DIR)/minidb/buddy.c \ $(GXPM_LIB_DIR)/minidb/compressor.cpp \ $(GXPM_LIB_DIR)/minidb/compr_lz4.cpp \ $(GXPM_LIB_DIR)/minidb/compr_lz77.cpp \ $(GXPM_LIB_DIR)/minidb/compr_lzo.cpp \ $(GXPM_LIB_DIR)/minidb/compr_zlib.cpp \ $(GXPM_LIB_DIR)/minidb/db.cpp \ $(GXPM_LIB_DIR)/minidb/hash.c \ $(GXPM_LIB_DIR)/minidb/io.cpp \ $(GXPM_LIB_DIR)/minidb/map.c \ $(GXPM_LIB_DIR)/textcode_convert.c \ LOCAL_SRC_FILES := \ $(GXPM_SRC_FILES) \ gomedia.cppLOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../../../common/GoxceedPM/zlib/include \ $(LOCAL_PATH)/../../../common/GoxceedPM/lz4 \ $(LOCAL_PATH)/../../../common/GoxceedPM/minilzo \ $(LOCAL_PATH)/../../../common/GoxceedPM/minidb \ $(LOCAL_PATH)/../../../common/GoxceedPM/core \ $(LOCAL_PATH)/../../../common/GoxceedPM \ LOCAL_LDLIBS := -llog LOCAL_MODULE := gomedia include $(BUILD_SHARED_LIBRARY)
Application.mk:
APP_ABI := allAPP_PLATFORM := android-8APP_STL := stlport_staticAPP_CPPFLAGS := -fpermissive
aa