Linker errors while using Opencv

I get linker errors while making a project with ofxOpenCv addon on Android Studio.Actually the example for OpenCv under Openframeworks examples directory works without problem.But if I add:

cv::VideoCapture cap;

to the code,then it gives linker errors when I try to Make/build the project.For Android I am using Openframeworks v0.11.0, I tried both with stable version and a nigtlybuild,no difference, also tried using Project Generator to make a new project,same problem.Same Opencv related codes run without problem on Windows using Openframeworks 0.9 for Windows. Ndk version r15, Android Sdk version 25.

The error messages:

Message Gradle Build:
Error:Execution failed for task ‘:linkOFAndroidAppArm64-v8aReleaseArm64SharedLibrary’.

A build operation failed.
Linker failed while linking libOFAndroidApp.so.
See the complete log at:

file:///J:/of_v0_11.0_nightlybuild/examples/android/androidOpenCVExample/build/tmp/linkOFAndroidApp

Arm64-v8aReleaseArm64SharedLibrary/output.txt
Error:error: linker command failed with exit code 1 (use -v to see invocation)

output.txt:
linking libOFAndroidApp.so failed.

J:\of_v0.11.0_android_release\apps\myApps\opencv2…\addons\ofxOpenCv\libs\opencv\lib\android\armeabi-v7a\libopencv_videoio.a(cap_images.cpp.o): In function
cv::CvCapture_Images::grabFrame()': /home/travis/build/openframeworks/apothecary/apothecary/build/opencv/modules/videoio/src/cap_images.cpp:(.text._ZN2cv16CvCapture_Images9grabFrameEv+0xe8): undefined reference to cv::imread(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, int)’

J:\of_v0.11.0_android_release\apps\myApps\opencv2…\addons\ofxOpenCv\libs\opencv\lib\android\armeabi-v7a\libopencv_videoio.a(cap_images.cpp.o): In function
`cv::CvCapture_Images::open(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&)’:/home/travis/build/openframeworks/apothecary/apothecary/build/opencv/modules/videoio/src/cap_images.cpp:

(.text._ZN2cv16CvCapture_Images4openERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+0x140): undefined reference to `cv::haveImageReader(std::__ndk1::basic_string<char,
std::__ndk1::char_traits, std::__ndk1::allocator > const&)’

J:\of_v0.11.0_android_release\apps\myApps\opencv2…\addons\ofxOpenCv\libs\opencv\lib\android\armeabi-v7a\libopencv_videoio.a(cap_images.cpp.o): In function
CvVideoWriter_Images::writeFrame(_IplImage const*)': /home/travis/build/openframeworks/apothecary/apothecary/build/opencv/modules/videoio/src/cap_images.cpp:(.text._ZN20CvVideoWriter_Images10writeFrameEPK9_IplImage+0x124): undefined reference to cv::imwrite(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > const&, cv::_InputArray const&, std::__ndk1::vector<int,
std::__ndk1::allocator > const&)’

J:\of_v0.11.0_android_release\apps\myApps\opencv2…\addons\ofxOpenCv\libs\opencv\lib\android\armeabi-v7a\libopencv_videoio.a(cap_images.cpp.o): In function
CvVideoWriter_Images::open(char const*)': /home/travis/build/openframeworks/apothecary/apothecary/build/opencv/modules/videoio/src/cap_images.cpp:(.text._ZN20CvVideoWriter_Images4openEPKc+0x140): undefined reference to cv::haveImageWriter(std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >
const&)’

J:\of_v0.11.0_android_release\apps\myApps\opencv2…\addons\ofxOpenCv\libs\opencv\lib\android\armeabi-v7a\libopencv_videoio.a(cap_mjpeg_decoder.cpp.o): In function
cv::MotionJpegCapture::retrieveFrame(int, cv::_OutputArray const&)': /home/travis/build/openframeworks/apothecary/apothecary/build/opencv/modules/videoio/src/cap_mjpeg_decoder.cpp:(.text._ZN2cv17MotionJpegCapture13retrieveFrameEiRKNS_12_OutputArrayE+0xbc): undefined reference to cv::imdecode(cv::_InputArray const&, int)’
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

Finished linkOFAndroidAppArmeabi-v7aReleaseArm7SharedLibrary, see full log

May it be that cv::VideoCapture not implemented for Android?

I think that the static lib that compes compiled in ofxOpencv does not include all the funcionatlity of openCv.

Why dont you use ofVideoGrabber or compile opencv and link ofxOpencv to your compiled version

1 Like

Thanks for your answer. Actualy what I want to do is to capture and display one frame from each video file, I think ofVideoGrabber is not used for this. I am not sure if I can compile the whole opencv library for android by myself.

Is there another way to capture and display a frame from each video file?There may be 1000 video files in a directory and my app should capture and display a frame from each video files.