mazend
mazend

Reputation: 464

undefined reference to `cv::error(int, std::string const&, char const*, char const*, int)'

I want to build an .so C++ library with link to OpenCV with Visual Studio. (My goal is to make an apk that uses the .so file in Unity)

I made cross-platform dynamic shared library project in Visual Studio and set proper project settings.

enter image description here In Linker > Input > Additional Dependencies, I added a path to the openCV .so file downloaded from here

In Visual Studio I can build below code.

void OpenCVForAndroid::TestMethod()
{
    cv::Mat img(10, 10, CV_8UC1);
}

However below code makes errors.

void OpenCVForAndroid::TestMethod()
{
    void* ddd = malloc(sizeof(int));
    cv::Mat img(100, 100, CV_8UC4, ddd);
}

1>C:\Users\ddd\Downloads\opencv-4.1.0-android-sdk\OpenCV-android-sdk\sdk\native\jni\include\opencv2/core/mat.inl.hpp:548: undefined reference to cv::error(int, std::string const&, char const*, char const*, int)

1>C:\Users\ddd\Downloads\opencv-4.1.0-android-sdk\OpenCV-android-sdk\sdk\native\jni\include\opencv2/core/mat.inl.hpp:561: undefined reference to cv::error(int, std::string const&, char const*, char const*, int)

This is because the constructor Mat (int rows, int cols, int type, void *data, size_t step=AUTO_STEP) contains cv::error and the linker failed to find it.

I thought libopencv_java4.so would have cv::error.. but maybe it doesn't.

What's wrong with my code or settings? Where is cv::error defined?

Thanks in advance :D

Upvotes: 1

Views: 1527

Answers (1)

mazend
mazend

Reputation: 464

I don't know the reason why the issue happened in version 4.1.0. However the issue was resolved after changing OpenCV version from 4.1.0 to 3.4.6.

Upvotes: 1

Related Questions