当前位置: 代码迷 >> Android >> NDK下STL编译不成功,怎么处理
  详细解决方案

NDK下STL编译不成功,怎么处理

热度:136   发布时间:2016-05-01 22:18:00.0
NDK下STL编译不成功,怎么办?
代码如下
C/C++ code
#include <string.h>#include <jni.h>#include <iostream>#include <vector>using namespace std;#ifndef _Included_com_example_hellojni_HelloJni#define _Included_com_example_hellojni_HelloJni#ifdef __cplusplusextern "C" {#endifjstringJava_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,                                                  jobject thiz ){    vector<int> vec; //只写这一行,还可以编译成功    vec.push_back(1);//一写这行,马上出下面一大堆错误    return env->NewStringUTF("Hello from JNI !");}#ifdef __cplusplus}#endif#endif

STL库也编译成功了。
写vector<int> vec;也可以编译成功。
但只要一写
vector<int> vec;
vec.push_back(1);
马上就出一大堆编译错误,如下:

Android NDK: WARNING: Rebuilding STLport libraries from sources!  
Android NDK: You might want to use $NDK/build/tools/build-stlport.sh  
Android NDK: in order to build prebuilt versions to speed up your builds!  
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : hello-jni <= hello-jni.cpp
make: 放弃循环依赖 /cygdrive/d/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a <- /cygdrive/d/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a 。
SharedLibrary : libhello-jni.so
D:/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib\libsupc++.a(eh_exception.o): In function `~exception':
/tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:31: multiple definition of `std::exception::~exception()'
D:/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a(dll_main.o):D:/android-ndk-r6/sources/cxx-stl/stlport/src/dll_main.cpp:65: first defined here
D:/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib\libsupc++.a(eh_exception.o): In function `~exception':
/tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:31: multiple definition of `std::exception::~exception()'
D:/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a(dll_main.o):D:/android-ndk-r6/sources/cxx-stl/stlport/src/dll_main.cpp:65: first defined here
D:/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib\libsupc++.a(eh_exception.o): In function `~bad_exception':
/tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:33: multiple definition of `std::bad_exception::~bad_exception()'
D:/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a(dll_main.o):D:/android-ndk-r6/sources/cxx-stl/stlport/src/dll_main.cpp:67: first defined here
D:/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib\libsupc++.a(eh_exception.o):(.data.rel.ro._ZTVSt13bad_exception+0x0): multiple definition of `vtable for std::bad_exception'
D:/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a(dll_main.o):(.data.rel.ro+0xf0): first defined here
D:/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib\libsupc++.a(eh_exception.o): In function `~bad_exception':
/tmp/ndk-digit/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:33: multiple definition of `std::bad_exception::~bad_exception()'
D:/android-ndk-r6/samples/hello-jni/obj/local/armeabi/libstlport_static.a(dll_main.o):D:/android-ndk-r6/sources/cxx-stl/stlport/src/dll_main.cpp:67: first defined here
  相关解决方案