#android #c #opencv #cmake #android-ndk
#Android #c #opencv #cmake #android-ndk
Вопрос:
Я пытаюсь добавить библиотеку opencv в свой собственный проект Android. Чтобы сделать это, я добавил путь к opencv в свой файл CMake
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
cmake_minimum_required(VERSION 3.4.1)
set(pathToOpenCv D:\OpenCV-android-sdk)
set(CMAKE VERBOSE MAKEFILE on)
set(CMAKE CXX FLAGS "${CMAKE_CXX_FLAGS} -std=gnu 11")
set(PARSER_TET_DIR ../../../co_FileCodec)
set(PARSER__DIR_ENGINE ../../../co_FileCodec_Engine/co_DecoderEngine)
set(PARSER_GWS_DIR ../../../GWStdLib)
include_directories(${pathToOpenCv}/sdk/native/jni/include)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION
${pathToOpenCv}/sdk/native/libs/${CMAKE_ANDROID_ARCH_ABI}/libopencv_java3.so)
set(decoder_engine_source
src/main/cpp/co_DecoderEngineAndroidApi.cpp
src/main/cpp/texture_decoder/texture_codec.cpp
src/main/cpp/util/util.cpp
)
add_library( # Sets the name of the library.
co_decoder_engine_android_lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${decoder_engine_source} )
# libcodec
set(_codec_source
${PARSER__DIR}/co_Decoder/co_MtrDecoder.cpp
${PARSER__DIR}/co_Decoder/co_Decoder.cpp
)
add_library(libcodec SHARED ${_codec_source})
include_directories(src/main/cpp)
include_directories(${PARSER__DIR})
include_directories(${PARSER__DIR}/co_Decoder)
include_directories(${PARSER__DIR}/co_Shared)
include_directories(${PARSER_GWS_DIR})
include_directories(${PARSER__DIR_ENGINE})
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_compile_options(co_decoder_engine_android_lib PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
target_compile_options(libcodec PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
target_link_libraries( # Specifies the target library.
co_decoder_engine_android_lib
mediandk
android
lib_opencv
libcodec
${log-lib} )
а затем я пытаюсь добавить это включение #include "opencv2/opencv.hpp"
в свой .cpp
файл
но я получаю такую ошибку
ninja: Entering directory `D:co_repocom_mainco_InfrastructureTier1.0co_FileCodec_EngineDecoderEngineBuilderco_decoder_engine_android.cxxcmakedebugx86'
[1/3] Building CXX object CMakeFiles/libcodec.dir/01a7033fdca6735bc52cb367da99f647/co_DecoderEngine/co_DecoderStream.cpp.o
[2/3] Linking CXX shared library ........buildintermediatescmakedebugobjx86liblibcodec.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/x86/liblibcodec.so
cmd.exe /C "cd . amp;amp; C:UserstrackAppDataLocalAndroidSdkndk20.0.5594570toolchainsllvmprebuiltwindows-x86_64binclang .exe --target=i686-none-linux-android24 --gcc-toolchain=C:/Users/track/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/track/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -std=c 17 -Wall -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,liblibcodec.so -o ........buildintermediatescmakedebugobjx86liblibcodec.so CMakeFiles/libcodec.dir/e17dc0da4ce9741e6542b9ad403a181e/co_FileCodec/co_Decoder/co_MtrDecoder.cpp.o CMakeFiles/libcodec.dir/e17dc0da4ce9741e6542b9ad403a181e/co_FileCodec/co_Decoder/co_Decoder.cpp.o CMakeFiles/libcodec.dir/a4eab3dee2189f67213cbef1e5027e5a/co_Decoder/co_DecoderImpl.cpp.o CMakeFiles/libcodec.dir/a4eab3dee2189f67213cbef1e5027e5a/co_Decoder/co_ChunkBuffers.cpp.o CMakeFiles/libcodec.dir/e17dc0da4ce9741e6542b9ad403a181e/co_FileCodec/co_Shared/co_Texture.cpp.o CMakeFiles/libcodec.dir/D_/co_repo/com_main/co_Infrastructure/Tier1.0/GWStdLib/GWS_Basics.cpp.o CMakeFiles/libcodec.dir/01a7033fdca6735bc52cb367da99f647/co_DecoderEngine/co_DecoderStream.cpp.o -latomic -lm amp;amp; cd ."
D:/OpenCV-android-sdk/sdk/native/jni/includeopencv2/core/cvstd.hpp:648: error: undefined reference to 'cv::String::deallocate()'
D:/OpenCV-android-sdk/sdk/native/jni/includeopencv2/core/cvstd.hpp:656: error: undefined reference to 'cv::String::deallocate()'
clang : error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Я уже все проверил, что я делаю не так?
Ответ №1:
Если nm
( dumpbin.exe
для Windows) видит cv::String::deallocate()
в libopencv_java3.so
:
$ nm -CD libopencv_java3.so | grep cv::String::deallocate
00000000003e3fa0 T cv::String::deallocate()
Это означает, что что-то не так с вашей упаковкой lib_opencv
. Давайте попробуем протестировать его с помощью реального абсолютного пути к libopencv_java3.so
(скопируйте его из вашей программы файлового менеджера) и добавьте его непосредственно в target_link_libraries(co_decoder_engine_android_lib ...)
и скомпилируйте для выбранного ABI.