android NDK:编译错误:libstdc ++:`std :: bad_exception ::〜bad_exception()'的多重定义

时间:2011-06-03 22:28:37

标签: android-ndk

使用android NDK编译c ++代码时出现以下错误:

/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `~exception':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:31: multiple definition of `std::exception::~exception()'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:65: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `~exception':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:31: multiple definition of `std::exception::~exception()'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:65: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `~bad_exception':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:33: multiple definition of `std::bad_exception::~bad_exception()'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:67: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/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'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):(.data.rel.ro+0xf0): first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `~bad_exception':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:33: multiple definition of `std::bad_exception::~bad_exception()'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:67: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `std::exception::what() const':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:46: multiple definition of `std::exception::what() const'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:68: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `std::bad_exception::what() const':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:52: multiple definition of `std::bad_exception::what() const'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:69: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `~exception':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:31: multiple definition of `std::exception::~exception()'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:65: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o): In function `~bad_exception':
/tmp/ndk/src/build/../gcc/gcc-4.4.3/libstdc++-v3/libsupc++/eh_exception.cc:33: multiple definition of `std::bad_exception::~bad_exception()'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):/tmp/ndk-toolchain/ndk-prebuilt-31319/sources/cxx-stl/stlport/src/dll_main.cpp:67: first defined here
/System/Library/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/lib/libsupc++.a(eh_exception.o):(.data.rel.ro._ZTVSt9exception+0x0): multiple definition of `vtable for std::exception'
/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libstlport_static.a(dll_main.o):(.data.rel.ro+0x108): first defined here
collect2: ld returned 1 exit status
make: *** [/Users/user/Documents/copperworkspace/Pinecone/obj/local/armeabi/libGenCertificate.so] Error 1

我在application.mk中使用APP_STL:= stlport_static 你们能帮忙吗?

2 个答案:

答案 0 :(得分:8)

我终于通过CPLUSPLUS-SUPPORT.html找到了答案。 stdc ++和stlport库中有异常类函数的多重定义。 因此,我不是静态添加stlport库,而是通过将Application.mk中的APP_STL更改为动态添加它: APP_STL:= stlport_shared

它解决了问题:)

答案 1 :(得分:0)

我遇到了同样的问题,但是Nishant Soni的解决方案还不够。

在向自己确认没有重复文件或多个声明后,我对解决所做的是执行Android Studio的清洁命令。 (构建 - >清理项目)。

导致问题的原因是可能我改变了项目的路径(移动了文件夹)

我花了很长时间才搞清楚。 希望它有所帮助!