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
?