编辑2 :找到正确的顺序,回到使用静态库
libavutil libavcodec libavformat libswresample libswscale dnn ml objdetect shape stitching superres videostab calib3d features2d highgui videoio imgcodecs ilmimf jpeg jasper png tiff webp video photo imgproc flann core tegra_hal log cpufeatures z
编辑1 :我放弃了这一点,并编译了大SHARED_LIBRARY libopencv_world.so
。
我正在尝试使用将AppCenter构建的OpenCV配置Android Studio React Native项目。
我正在使用Mac。因为将为我提供一个代理(在我的情况下为mac OSX)在云中构建项目,所以所有代码和静态库依赖项都应来自源存储库。 AFAIK由于这种无服务器环境,我无法使用find_package(),对吗?
我已经下载了OpenCV Android SDK,其中包含与静态库链接所需的所有内容。
我的问题是我需要正确排序OpenCV静态库,以完成链接阶段。我找不到这些库的完整正确排序的列表。但我找到了一种tell the linker to figure it out的方法。
这是我到目前为止的位置。首先是CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.4.1)
# CMAKE_SOURCE_DIR : this is the directory which contains the top-level CMakeLists.txt, i.e. the top level source directory. In this case the andoid/app folder.
# set OpenCV Static Libraries Environment Variables
#set(OpenCV_STATIC_LIBS_DIR ${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI})
#set(OpenCV_STATIC_3RDPARTY_LIBS_DIR ${CMAKE_HOME_DIRECTORY}/src/opencv/3rdparty/libs/${ANDROID_ABI})
add_library(tbb
STATIC
IMPORTED)
add_library(highgui
STATIC
IMPORTED)
add_library(calib3d
STATIC
IMPORTED)
add_library(core
STATIC
IMPORTED)
add_library(dnn
STATIC
IMPORTED)
add_library(flann
STATIC
IMPORTED)
add_library(imgproc
STATIC
IMPORTED)
add_library(videoio
STATIC
IMPORTED)
add_library(imgcodecs
STATIC
IMPORTED)
add_library(features2d
STATIC
IMPORTED)
add_library(ml
STATIC
IMPORTED)
add_library(photo
STATIC
IMPORTED)
add_library(shape
STATIC
IMPORTED)
add_library(objdetect
STATIC
IMPORTED)
add_library(stitching
STATIC
IMPORTED)
set_target_properties(tbb
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/3rdparty/libs/${ANDROID_ABI}/libtbb.a)
set_target_properties(highgui
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_highgui.a)
set_target_properties(calib3d
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_calib3d.a)
set_target_properties(core
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_core.a)
set_target_properties(dnn
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_dnn.a)
set_target_properties(flann
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_flann.a)
set_target_properties(imgproc
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_imgproc.a)
set_target_properties(videoio
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_videoio.a)
set_target_properties(imgcodecs
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_imgcodecs.a)
set_target_properties(features2d
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_features2d.a)
set_target_properties(ml
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_ml.a)
set_target_properties(photo
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_photo.a)
set_target_properties(shape
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_shape.a)
set_target_properties(objdetect
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_objdetect.a)
set_target_properties(stitching
PROPERTIES
IMPORTED_LOCATION
${CMAKE_HOME_DIRECTORY}/src/opencv/staticlibs/${ANDROID_ABI}/libopencv_stitching.a)
# ROOT would be react-native-djinius/deps/djinni
#
set( ROOT "${CMAKE_SOURCE_DIR}/../../deps/djinni" )
# PROJECT_ROOT would be react-native-djinius
set( PROJECT_ROOT "${CMAKE_SOURCE_DIR}/../.." )
# SUPPORT_LIB_ROOT would be
set( SUPPORT_LIB_ROOT "${ROOT}/support-lib" )
file( GLOB JNI_CODE "../../generated-src/jni/*.cpp" )
file( GLOB PROJECT_CODE "${PROJECT_ROOT}/src/cpp/*.cpp" "${PROJECT_ROOT}/generated-src/cpp/*.cpp" )
file( GLOB PROJECT_HEADERS "${PROJECT_ROOT}/src/cpp/*.hpp" "${PROJECT_ROOT}/generated-src/cpp/*.hpp" )
file( GLOB DJINNI_CODE "${SUPPORT_LIB_ROOT}/cpp/*.cpp" "${SUPPORT_LIB_ROOT}/jni/*.cpp" )
file( GLOB DJINNI_HEADERS "${SUPPORT_LIB_ROOT}/cpp/*.hpp" "${SUPPORT_LIB_ROOT}/jni/*.hpp" )
include_directories(
"${SUPPORT_LIB_ROOT}/cpp"
"${SUPPORT_LIB_ROOT}/jni"
"${PROJECT_ROOT}/src/cpp"
"${PROJECT_ROOT}/generated-src/cpp"
"${CMAKE_SOURCE_DIR}/src/opencv"
)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
${JNI_CODE}
${DJINNI_CODE}
${DJINNI_HEADERS}
${PROJECT_CODE}
${PROJECT_HEADERS}
)
# link addional static libraries
target_link_libraries(native-lib -Wl,--start-group tbb core imgproc imgcodecs videoio highgui video calib3d features2d objdetect dnn ml flann photo stitching -Wl,--end-group)
基本上,它什么也没找到:( 我尝试删除
-Wl,--start-group ... -Wl,-endgroup
仅包含库,结果是相同的。
接下来是失败的构建的输出(仅链接部分):
error: undefined reference to 'cv::imencode(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<unsigned char, std::__ndk1::allocator<unsigned char> >&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::is_group_execution_cancelled() const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface5::internal::task_base::destroy(tbb::task&)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::~task_group_context()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface7::internal::task_arena_base::internal_terminate()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface7::internal::task_arena_base::internal_initialize()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::reset()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::reset()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::is_group_execution_cancelled() const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface5::internal::task_base::destroy(tbb::task&)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::~task_group_context()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface7::internal::task_arena_base::internal_terminate()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::interface7::internal::task_arena_base::internal_initialize()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::reset()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(alloc.cpp.o):alloc.cpp:function tbb::flow::interface10::graph::~graph(): error: undefined reference to 'tbb::task_group_context::reset()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) [clone .part.10]: error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::error(cv::Exception const&): error: undefined reference to '__android_log_print'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::TLSData<cv::(anonymous namespace)::ThreadID>::createDataInstance() const: error: undefined reference to '__itt_thread_set_name_ptr__3_0'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'ippicvGetCpuFeatures'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'ippicvInit'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'ippicvGetEnabledCpuFeatures'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'ippicviGetLibVersion'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'ippicvSetCpuFeatures'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::cerr'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::put(char)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::flush()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::cerr'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::put(char)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::flush()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::cerr'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::put(char)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::flush()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::__throw_bad_cast()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::__throw_bad_cast()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::__throw_bad_cast()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function cv::TLSDataContainer::getData() const: error: undefined reference to 'std::__throw_length_error(char const*)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function _GLOBAL__sub_I_system.cpp: error: undefined reference to 'std::ios_base::Init::Init()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(system.cpp.o):system.cpp:function _GLOBAL__sub_I_system.cpp: error: undefined reference to 'std::ios_base::Init::~Init()'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) [clone .part.46]: error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
../../../../src/opencv/staticlibs/x86/libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::~basic_stringbuf(): error: undefined reference to 'vtable for std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
这种方法有什么问题? 感谢您的帮助。