链接到Android上的ceres库

时间:2015-10-09 11:20:46

标签: android c++ android-ndk qt-creator ceres-solver

我正在尝试将ceres解算器编译并部署到Android项目中。

我成功编译了ceres(1.8.0和1.9.0,尝试过两者),从ceres jni文件夹运行ndk-build。

然后,我使用QtCreator来编译和部署Android项目。它失败并出现以下错误:

B:\Android\android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ --sysroot=B:\Android\android-ndk-r10e/platforms/android-9/arch-arm/ -Wl,-soname,libtest_3rdparty_inprg_ceres.so -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libtest_3rdparty_inprg_ceres.so main.obj logging.obj   -LB:\Android\android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a -LB:\Android\android-ndk-r10e/platforms/android-9/arch-arm//usr/lib -lb:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a -LC:/Qt/5.5/android_armv7/lib -lQt5Widgets -Lc:\utils\android\ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -Lc:\utils\android\ndk/platforms/android-9/arch-arm//usr/lib -lQt5Gui -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:3639: error: undefined reference to 'std::__1::__shared_weak_count::~__shared_weak_count()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4448: error: undefined reference to 'std::__1::__shared_weak_count::__release_shared()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4154: error: undefined reference to 'std::__1::__shared_weak_count::__add_shared()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory:4154: error: undefined reference to 'std::__1::__shared_weak_count::__add_shared()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::ios_base::getloc() const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::locale::~locale()'
B:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/jni/../internal/ceres/solver_impl.cc:123: error: undefined reference to 'std::__1::cout'
B:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/jni/../internal/ceres/solver_impl.cc:123: error: undefined reference to 'std::__1::ctype<char>::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::ios_base::getloc() const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::locale::~locale()'
B:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/jni/../internal/ceres/solver_impl.cc:158: error: undefined reference to 'std::__1::cout'
B:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/jni/../internal/ceres/solver_impl.cc:158: error: undefined reference to 'std::__1::ctype<char>::id'
b:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a(solver_impl.o):solver_impl.cc:vtable for std::__1::__shared_ptr_pointer<ceres::OrderedGroups<double*>*, std::__1::default_delete<ceres::OrderedGroups<double*> >, std::__1::allocator<ceres::OrderedGroups<double*> > >: error: undefined reference to 'std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:508: error: undefined reference to 'std::__1::ios_base::getloc() const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:508: error: undefined reference to 'std::__1::locale::~locale()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::ios_base::getloc() const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__locale:174: error: undefined reference to 'std::__1::locale::use_facet(std::__1::locale::id&) const'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:734: error: undefined reference to 'std::__1::locale::~locale()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:520: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:520: error: undefined reference to 'std::__1::ctype<char>::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/streambuf:370: error: undefined reference to 'std::__1::locale::locale()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__hash_table:1944: error: undefined reference to 'std::__1::__next_prime(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__hash_table:1955: error: undefined reference to 'std::__1::__next_prime(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__hash_table:1944: error: undefined reference to 'std::__1::__next_prime(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/__hash_table:1955: error: undefined reference to 'std::__1::__next_prime(unsigned int)'
b:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a(schur_eliminator.o):schur_eliminator.cc:vtable for ceres::internal::SchurEliminator<2, 4, 8>: error: undefined reference to 'ceres::internal::SchurEliminator<2, 4, 8>::~SchurEliminator()'
b:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a(schur_eliminator.o):schur_eliminator.cc:vtable for ceres::internal::SchurEliminator<2, 4, 8>: error: undefined reference to 'ceres::internal::SchurEliminator<2, 4, 8>::~SchurEliminator()'
b:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a(schur_eliminator.o):schur_eliminator.cc:vtable for ceres::internal::SchurEliminator<2, 4, 8>: error: undefined reference to 'ceres::internal::SchurEliminator<2, 4, 8>::Init(int, ceres::internal::CompressedRowBlockStructure const*)'
b:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a(schur_eliminator.o):schur_eliminator.cc:vtable for ceres::internal::SchurEliminator<2, 4, 8>: error: undefined reference to 'ceres::internal::SchurEliminator<2, 4, 8>::Eliminate(ceres::internal::BlockSparseMatrix const*, double const*, double const*, ceres::internal::BlockRandomAccessMatrix*, double*)'
b:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/lib/android_armeabi-v7a/gcc-4.8/libceres.a(schur_eliminator.o):schur_eliminator.cc:vtable for ceres::internal::SchurEliminator<2, 4, 8>: error: undefined reference to 'ceres::internal::SchurEliminator<2, 4, 8>::BackSubstitute(ceres::internal::BlockSparseMatrix const*, double const*, double const*, double const*, double*)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3077: error: undefined reference to 'std::__1::__rs_get()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:2912: error: undefined reference to 'std::__1::__rs_default::operator()()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:2912: error: undefined reference to 'std::__1::__rs_default::operator()()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3083: error: undefined reference to 'std::__1::__rs_default::~__rs_default()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3077: error: undefined reference to 'std::__1::__rs_get()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:2912: error: undefined reference to 'std::__1::__rs_default::operator()()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:2912: error: undefined reference to 'std::__1::__rs_default::operator()()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3083: error: undefined reference to 'std::__1::__rs_default::~__rs_default()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3077: error: undefined reference to 'std::__1::__rs_get()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3083: error: undefined reference to 'std::__1::__rs_default::~__rs_default()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3077: error: undefined reference to 'std::__1::__rs_get()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/algorithm:3083: error: undefined reference to 'std::__1::__rs_default::~__rs_default()'
B:/dev/vobs_ext/libcpp/ceres/ceres-solver-1.9.0/jni/../internal/ceres/partitioned_matrix_view.cc:118: error: undefined reference to 'ceres::internal::PartitionedMatrixView<2, 4, 8>::PartitionedMatrixView(ceres::internal::BlockSparseMatrix const&, int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:661: error: undefined reference to 'std::__1::ios_base::~ios_base()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/streambuf:370: error: undefined reference to 'std::__1::locale::locale()'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:524: error: undefined reference to 'std::__1::ios_base::clear(unsigned int)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:494: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:494: error: undefined reference to 'std::__1::ctype<char>::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:728: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ostream:676: error: undefined reference to 'std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
B:/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/ios:668: error: undefined reference to 'std::__1::ios_base::init(void*)'
collect2.exe: error: ld returned 1 exit status
makefile:82: recipe for target 'libtest_3rdparty_inprg_ceres.so' failed
mingw32-make: *** [libtest_3rdparty_inprg_ceres.so] Error 1
13:17:13: Le processus "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet test_3rdparty_inprg_ceres (kit : Android for armeabi-v7a (GCC 4.9, Qt 5.5.0))
When executing step "Make"
13:17:13: Temps écoulé : 00:08.

我想知道这是否可能是由于静态链接c ++库,而我的程序动态链接....但不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

应用中的所有库应该使用相同的STL运行时。但是谈到静态库,它们必须使用相同的STL配置。如果您没有更改cerces-solver / jni / Application.mk,则会发现 APP_STL=c++_static 。您可以覆盖它以使用 APP_STL=c++_shared ,但您需要一个很好的理由来更改此外部库的构建方式。将程序切换为 APP_STL=c++_static 会更容易。

由jpo38编辑: 实际上还有其他事情需要改变才能生成libceres.so而不是libceres.a:

  • 在Android.mk
  • 中添加LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
  • 在Android.mk
  • 中将include $(BUILD_STATIC_LIBRARY)替换为include $(BUILD_SHARED_LIBRARY)
  • 在Android.mk中向-DCERES_BUILDING_SHARED_LIBRARY添加-DCERES_RESTRICT_SCHUR_SPECIALIZATIONLOCAL_CFLAGS(dunno为什么第二个有帮助,看起来像Shur的东西不喜欢共享链接)

然后,生成并可以使用动态库。