0

I have seen the similar questions undefined reference to std::ios_base::Init::Init() and undefined reference to `std::ios_base::Init::Init()' but I'm not sure whether I have the same situation.

I'm configuring opencv for android 3.4.7 on Android Studio 3.5. I imported libs of opencv by editing CMakeList.txt and build.gradle:

set(opencv_version OpenCV3-android-sdk)

set(OpenCV_STATIC ON)
set(OpenCV_DIR /home/lynx/Android/Proj/${opencv_version}/sdk/native/jni)
find_package(OpenCV REQUIRED)
if (OpenCV_FOUND)
    message(WARNING "opencv libs: ${OpenCV_LIBS}")
else (OpenCV_FOUND)
    message(WARNING "opencv not found!")
endif(OpenCV_FOUND)

target_link_libraries(
        ${OpenCV_LIBS})
sourceSets {
    main {
        jniLibs.srcDirs = ['/home/lynx/Android/Proj/OpenCV3-android-sdk/sdk/native/libs']
    }
}

and my native-lib.cpp is

#include <jni.h>
#include <string>
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace cv;

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_stitch_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {

    std::string hello = "Hello from OpenCV " + (std::string)CV_VERSION;

    return env->NewStringUTF(hello.c_str());
}

When building the project it shows many undefined reference errors from the file of opencv. It seems not the problem of linking cpp files with c linker: it called clang++ to do the task and when not using opencv, the project can be build successful.

So is it because that I didn't correctly configured opencv?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
嬲你屋里娘
  • 303
  • 2
  • 7

1 Answers1

0

This is usually a case of using a library built against a different STL than you're using. I can't tell with the information you've given, but there are a lot of other questions on SO where people build their app with libc++ but build opencv with libstdc++. These are not compatible. See NDK - problems after GNUSTL has been removed from the NDK (revision r18).

Dan Albert
  • 10,079
  • 2
  • 36
  • 79