2

EDIT 2: Found the correct order, back to using static libs

 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

EDIT 1: I gave up on this, and compiled the big SHARED_LIBRARY libopencv_world.so.


I'm trying to configure an Android Studio React Native project using OpenCV to be built with AppCenter.

I'm working on a mac. Because an agent (mac OSX in my case) will be provisioned for me to build my project in the cloud, all the code and static libraries dependencies should come from the source repository. AFAIK I can't use find_package() in my case because of this serverless environment, right?

I've downloaded the OpenCV Android SDK which contains everything I need to link with the static libraries.

My problem is that I need the OpenCV static libraries to be properly ordered for the link phase to complete. I can't find a complete properly ordered list of those libraries. But I found a way to tell the linker to figure it out.

Here is where I am so far. First the CMakeLists.txt file:

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)

Basically, it finds nothing :( I've tried removing

-Wl, --start-group ... -Wl,--endgroup

to only include the libraries and the result is the same.

Next is the output of the failed build (link part only):

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> >'

What is wrong with this approach? Thanks for your help.

0 Answers0