android - 链接到 Android 上的 ceres 库

标签 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.

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

最佳答案

您应用中的所有库都应该使用相同的 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)
  • 添加 -DCERES_BUILDING_SHARED_LIBRARY-DCERES_RESTRICT_SCHUR_SPECIALIZATION(不知道为什么第二个有用,看起来 Shur 的东西不喜欢共享链接)到 LOCAL_CFLAGS在 Android.mk 中

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

关于android - 链接到 Android 上的 ceres 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33036970/

相关文章:

android - 如何获取 Android 的传感器值

Android studio - 可以复制布局

java - 使 native 代码访问java方法和数据成员

android - 调用 GLSurfaceView.onPause() 后 Activity 暂停超时

android - ldd 在 android 上等效

android - 在 View 中调整 SVG 图像的大小

android - 是否可以在 Android Wear 上显示 Google map View ?

c++ - 任务计划程序 : How to schedule a task to execute at login

c++ - 在 Visual Studio 中使用 __asm 返回 float 堆栈中的 double 值

c++ - 从 RAII 对象泄漏资源