Description
Hi, i'm trying to use gocv with gomobile and Android, but in the last step (gomobile binding), I get some undefined references on cv::DescriptorMatcher::knnMatch
and others..
Is there some configuration on CMake step I could be missing?
Please read below for explanation of all the steps I followed up to the linker errors.
Thanks!
Steps followed to build from sources
I followed gocv build from sources instructions with some tweaks to obtain abi-armeabi-v7a shared libs.
The CMake configuration used is here.
After compilation I obtain all the needed .so files with the correct abi.
Hello world gomobile project
The gomobile project is nothing fancy, just a hello world:
package mobiletest
import (
"log"
"gocv.io/x/gocv"
)
func Version(){
//This line should output on Android Logcat like "GoLog: opencv lib version: 3.4.1"
log.Printf("opencv lib version: %s\n", gocv.OpenCVVersion())
}
Android java bindings with gomobile
To generate mobiletest
package Java bindings for Android, I follow gomobile steps and call gomobile
like this:
@echo OFF
set "HERE=%~dp0"
set "HERE=%HERE:\=/%"
set GO_PACKAGE="mobiletest"
set AAR_OUTPUT_PATH="../android/app/libs"
set AAR_OUTPUT_FILENAME="mobiletest.aar"
set TARGET=android/arm
set CGO_CXXFLAGS=--std=c++11
set CGO_CPPFLAGS=-I%HERE%../opencv/include
set CGO_LDFLAGS=-L%HERE%../opencv/libs/armeabi-v7a -lopencv_core -lopencv_face -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn -lopencv_xfeatures2d -lopencv_plot -lopencv_tracking -lopencv_img_hash
gomobile.exe bind -target %TARGET% -tags customenv -v -o "%AAR_OUTPUT_PATH%/%AAR_OUTPUT_FILENAME%" %GO_PACKAGE%
Linker errors
But I get some undefined references
from the linker:
runtime/cgo
golang.org/x/mobile/internal/mobileinit
gocv.io/x/gocv
golang.org/x/mobile/bind/java
# gocv.io/x/gocv
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x014.o:features2d.cpp:function BFMatcher_KnnMatch: error: undefined reference to 'cv::DescriptorMatcher::knnMatch(cv::_InputArray const&, cv::_InputArray const&, std::__ndk1::vector<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> >, std::__ndk1::allocator<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> > > >&, int, cv::_InputArray const&, bool) const'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x014.o:features2d.cpp:function BFMatcher_KnnMatchWithParams(cv::Ptr<cv::BFMatcher>*, cv::Mat*, cv::Mat*, int, cv::Mat*, bool): error: undefined reference to 'cv::DescriptorMatcher::knnMatch(cv::_InputArray const&, cv::_InputArray const&, std::__ndk1::vector<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> >, std::__ndk1::allocator<std::__ndk1::vector<cv::DMatch, std::__ndk1::allocator<cv::DMatch> > > >&, int, cv::_InputArray const&, bool) const'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x015.o:highgui.cpp:function Window_SelectROIs: error: undefined reference to 'cv::selectROIs(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<cv::Rect_<int>, std::__ndk1::allocator<cv::Rect_<int> > >&, bool, bool)'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x016.o:imgcodecs.cpp:function Image_IMWrite: error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x016.o:imgcodecs.cpp:function Image_IMWrite_WithParams: error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x016.o:imgcodecs.cpp:function Image_IMEncode: 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&)'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x018.o:objdetect.cpp:function CascadeClassifier_DetectMultiScale: error: undefined reference to 'cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__ndk1::vector<cv::Rect_<int>, std::__ndk1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x018.o:objdetect.cpp:function CascadeClassifier_DetectMultiScaleWithParams: error: undefined reference to 'cv::CascadeClassifier::detectMultiScale(cv::_InputArray const&, std::__ndk1::vector<cv::Rect_<int>, std::__ndk1::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)'
C:\Users\Gero\AppData\Local\Temp\go-build199540534\b032\_x018.o:objdetect.cpp:function GroupRectangles: error: undefined reference to 'cv::groupRectangles(std::__ndk1::vector<cv::Rect_<int>, std::__ndk1::allocator<cv::Rect_<int> > >&, int, double)'
clang60++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
gomobile.exe: go build -tags customenv -v -buildmode=c-shared -o=C:\Users\Gero\AppData\Local\Temp\gomobile-work-903591099\android\src\main\jniLibs\armeabi-v7a\libgojni.so gobind failed: exit status 2
Press any key to continue . . .
My Environment
- Operating System and version: Microsoft Windows 10 Enterprise 2016 LTSB (Version 10.0.14393 Build 14393)
- OpenCV version used: opencv-3.4.1 / opencv_contrib-3.4.1
- GoCV version used: 0.13.1
- Go version: go version go1.10.3 windows/amd64
CMake output
General configuration for OpenCV 3.4.1 =====================================
Version control: unknown
Extra modules:
Location (extra): D:/SDK/opencv/opencv_contrib-3.4.1/modules
Version control (extra): unknown
Platform:
Timestamp: 2018-06-16T05:01:37Z
Host: Windows 10.0.14393 AMD64
Target: Android 1 armv7-a
CMake: 3.11.3
CMake generator: MinGW Makefiles
CMake build tool: D:/SDK/mingw-w64/x86_64-7.3.0-posix-seh-rt_v5-rev0/mingw64/bin/mingw32-make.exe
Configuration: Release
CPU/HW features:
Baseline:
requested: DETECT
disabled: VFPV3 NEON
C/C++:
Built as dynamic libs?: YES
C++11: YES
C++ Compiler: D:/SDK/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++.exe (ver 4.9.0)
C++ flags (Release): -fexceptions -frtti -Wno-psabi --sysroot=D:/SDK/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack -DANDROID -D__ANDROID_API__=16 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fexceptions -frtti -Wno-psabi --sysroot=D:/SDK/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack -DANDROID -D__ANDROID_API__=16 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG -DDEBUG -D_DEBUG
C Compiler: D:/SDK/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc.exe
C flags (Release): -fexceptions -Wno-psabi --sysroot=D:/SDK/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack -DANDROID -D__ANDROID_API__=16 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -mthumb -fomit-frame-pointer -fno-strict-aliasing -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fexceptions -Wno-psabi --sysroot=D:/SDK/Android/sdk/ndk-bundle/platforms/android-16/arch-arm -funwind-tables -finline-limit=64 -fsigned-char -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fdata-sections -ffunction-sections -Wa,--noexecstack -DANDROID -D__ANDROID_API__=16 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -marm -fno-omit-frame-pointer -fno-strict-aliasing -O0 -g -DDEBUG -D_DEBUG -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
Linker flags (Debug): -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
ccache: NO
Precompiled headers: NO
Extra dependencies: dl m log
3rdparty dependencies:
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: js saliency world
Disabled by dependency: -
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern freetype hdf java matlab ovis python2 python3 sfm viz
Applications: -
Documentation: NO
Non-free algorithms: NO
Android:
Android ABI: armeabi-v7a
STL type: gnustl_static
Native API level: android-16
SDK target: android_sdk_target_status-NOTFOUND
Android NDK: D:/SDK/Android/sdk/ndk-bundle (toolchain: arm-linux-androideabi-4.9)
android tool: NO
GUI:
Media I/O:
ZLib: build (ver 1.2.11)
JPEG: build (ver 90)
WEBP: build (ver encoder: 0x020e)
PNG: build (ver 1.6.34)
TIFF: build (ver 42 - 4.0.9)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
Video I/O:
Parallel framework: pthreads
Trace: YES (built-in)
Other third-party libraries:
Custom HAL: NO
Protobuf: build (3.5.1)
NVIDIA CUDA: NO
Python (for build): C:/Python27/python.exe
Java:
ant: NO
Java wrappers: NO
Java tests: NO
Install to: D:/SDK/opencv/build_android_arm/install
-----------------------------------------------------------------