NDK R5编译STL的问题

sward2005 2011-01-04 03:06:41
最近要用NDK R5编译C++程序,NDK R4是不支持stl的,但用R5的时候编译以下程序出错,有哪位大侠帮忙看一下。




#include "com_Android_oray_First_FirstAndroid.h"
#include <list>
#include <vector>

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT void JNICALL Java_com_Android_oray_First_FirstAndroid_testJni(JNIEnv *, jobject)

{
std::vector<int> vecTest;
vecTest.push_back(1);
}

#ifdef __cplusplus
}
#endif



错误如下:

D:/bwy/workspace/FirstAndroid/obj/local/armeabi/objs/first_jni/com_Android_oray_
First_FirstAndroid.o: In function `std::__node_alloc::allocate(unsigned int&)':
E:/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/
stlport/stlport/stl/_alloc.h:158: undefined reference to `std::__node_alloc::_M_
allocate(unsigned int&)'
D:/bwy/workspace/FirstAndroid/obj/local/armeabi/objs/first_jni/com_Android_oray_
First_FirstAndroid.o: In function `std::__node_alloc::deallocate(void*, unsigned
int)':
E:/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/
stlport/stlport/stl/_alloc.h:161: undefined reference to `std::__node_alloc::_M_
deallocate(void*, unsigned int)'
E:/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/
stlport/stlport/stl/_alloc.h:161: undefined reference to `std::__node_alloc::_M_
deallocate(void*, unsigned int)'
E:/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/
stlport/stlport/stl/_alloc.h:161: undefined reference to `std::__node_alloc::_M_
deallocate(void*, unsigned int)'
collect2: ld returned 1 exit status
make: *** [/bwy/workspace/FirstAndroid/obj/local/armeabi/libfirst_jni.so] Error
1


后来搜了一下,有个老外说要在.mk文件中加一些选项
我照加了还是不行
.mk文件如下:
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := first_jni
LOCAL_SRC_FILES := com_Android_oray_First_FirstAndroid.cpp
LOCAL_LDLIBS := \
-lm -llog \
-L /cygdrive/e/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/stlport/libs/armeabi/libstlport_shared.so #这个是stlport里的动态lib

LOCAL_CPPFLAGS := -D_STLP_USE_SIMPLE_NODE_ALLOC #这个是老外说要加的,防止出我上面说的错误,我加了无果

APP_CPPFLAGS += -fexceptions
APP_STL := stlport_shared
APP_CPPFLAGS += -frtti

LOCAL_C_INCLUDES += \
/cygdrive/e/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/stlport/stlport \#这个是stlport里的头文件

$(JNI_H_INCLUDE)

include $(BUILD_SHARED_LIBRARY)


跪求答案啊。。。
...全文
2309 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
winson007_liu 2011-05-19
  • 打赏
  • 举报
回复
楼主问题解决了吗?
xqs007 2011-01-13
  • 打赏
  • 举报
回复
-L /cygdrive/e/Software/android.setup/android-ndk-r5-windows/android-ndk-r5/sources/cxx-stl/stlport/libs/armeabi/ -lstlport_shared
sward2005 2011-01-04
  • 打赏
  • 举报
回复
啊,刚看了一下,兄台万分感谢啊,是我没看清。。。。
zhuzeitou 2011-01-04
  • 打赏
  • 举报
回复
doc里的原话如下

[QUOTE]By default, the headers and libraries for the minimal C++ runtime system
library (/system/lib/libstdc++.so) are used when building C++ sources.

You can however select a different implementation by setting the variable
APP_STL to something else in your Application.mk, for example:

APP_STL := stlport_static

To select the static STLport implementation provided with this NDK.
Value APP_STL values are the following:

system -> Use the default minimal C++ runtime library.
stlport_static -> Use STLport built as a static library.
stlport_shared -> Use STLport built as a shared library.
[/QUOTE]
zhuzeitou 2011-01-04
  • 打赏
  • 举报
回复
APP_CPPFLAGS += -fexceptions
APP_STL := stlport_shared
APP_CPPFLAGS += -frtti

这种app的都不是放在android.mk里的,而是application.mk里

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧