Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译Android报错 #166

Open
7288Fzq opened this issue Nov 17, 2024 · 2 comments
Open

编译Android报错 #166

7288Fzq opened this issue Nov 17, 2024 · 2 comments

Comments

@7288Fzq
Copy link

7288Fzq commented Nov 17, 2024

编译时报错:

(base) tony@ubuntu:~/Downloads/Android/HelloWorld/build$ make -j8
[ 50%] Building CXX object CMakeFiles/hello-world.dir/src/main.cpp.o
[100%] Linking CXX executable hello-world
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(matrix.cpp.o):matrix.cpp:function std::__ndk1::__throw_length_error[abi:nn180000](char const*): error: undefined reference to 'std::__ndk1::__libcpp_verbose_abort(char const*, ...)'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(matrix_transform.cpp.o):matrix_transform.cpp:function std::__throw_bad_array_new_lengthabi:nn180000: error: undefined reference to 'std::__ndk1::__libcpp_verbose_abort(char const*, ...)'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to 'std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >::str() const'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function std::__ndk1::__throw_out_of_range[abi:nn180000](char const*): error: undefined reference to 'std::__ndk1::__libcpp_verbose_abort(char const*, ...)'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >::str() const'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'vtable for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >::str() const'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::HWFeatures::initialize(): error: undefined reference to 'std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >::str() const'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(check.cpp.o):check.cpp:function std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >::basic_stringstreamabi:nn180000: error: undefined reference to 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(check.cpp.o):check.cpp:function std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >::basic_stringstreamabi:nn180000: error: undefined reference to 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(check.cpp.o):check.cpp:function cv::detail::check_failed_MatType(int, int, cv::detail::CheckContext const&): error: undefined reference to 'VTT for std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(check.cpp.o):check.cpp:function cv::detail::check_failed_MatType(int, int, cv::detail::CheckContext const&): error: undefined reference to 'vtable for std::__ndk1::basic_stringbuf<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(logger.cpp.o):logger.cpp:function cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LogLevel, char const*): error: undefined reference to 'VTT for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(logger.cpp.o):logger.cpp:function cv::utils::logging::internal::writeLogMessage(cv::utils::logging::LogLevel, char const*): error: undefined reference to 'vtable for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(logger.cpp.o):logger.cpp:function cv::utils::logging::internal::writeLogMessageEx(cv::utils::logging::LogLevel, char const*, char const*, int, char const*, char const*): error: undefined reference to 'VTT for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(logger.cpp.o):logger.cpp:function cv::utils::logging::internal::writeLogMessageEx(cv::utils::logging::LogLevel, char const*, char const*, int, char const*, char const*): error: undefined reference to 'vtable for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(parallel.cpp.o):parallel.cpp:function cv::parallel::ParallelBackendRegistry::dumpBackends() const: error: undefined reference to 'VTT for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(parallel.cpp.o):parallel.cpp:function cv::parallel::ParallelBackendRegistry::dumpBackends() const: error: undefined reference to 'vtable for std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_highgui.a(highgui.cpp.o):highgui.cpp:function cv::imread(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, int): error: undefined reference to 'vtable for std::__ndk1::basic_istringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
/home/tony/Downloads/Android/android-ndk-r21e-linux-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: the vtable symbol may be undefined because the class is missing its key function
/home/tony/Downloads/Android/HelloWorld/opencv-mobile-4.10.0-android/sdk/native/staticlibs/armeabi-v7a/libopencv_highgui.a(highgui.cpp.o):highgui.cpp:function cv::imread(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, int): error: undefined reference to 'VTT for std::__ndk1::basic_istringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/hello-world.dir/build.make:105: hello-world] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/hello-world.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

请问一下原因!谢谢。使用的工具是android-ndk-r21e-linux-x86_64
cmakelists:

`cmake_minimum_required(VERSION 3.10)

project(HelloWorld)

设置为 Android 架构

set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21)

设置 STL 类型为静态库

#set(CMAKE_ANDROID_STL_TYPE c++_static)

设置编译选项,以确保生成的程序为 Position Independent Executable (PIE)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")

set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/opencv-mobile-4.10.0-android/sdk/native/jni)
find_package(OpenCV REQUIRED)

添加源文件

add_executable(hello-world src/main.cpp)

target_link_libraries(hello-world ${OpenCV_LIBS})
`

@copper202310
Copy link

解决了吗,我也遇到这个问题

@nihui
Copy link
Owner

nihui commented Jan 11, 2025

更新 ndk r27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants