gocv
gocv copied to clipboard
Working with mobile
Hi,
I want to cross my so so it can be used at mobile, let's say Android, is there any other for I need to get into the Android device, or cross cooking will work smoothly?
I've my GO lib that is running at Android through JNI, once I tried to use gocv
in that lib, and croos compile my code, I got:
CGO_ENABLED=1 \
GOOS=android \
GOARCH=arm \
GOARM=7 \
CC=/Users/hajsf/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang \
go build -ldflags="-w" -buildmode=c-shared -o ../cocoon/app/src/main/jniLibs/armeabi-v7a/libfoo.so myapp
# gocv.io/x/gocv
ld: warning: ld: warning: ignoring file $WORK/b036/_x001.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )ignoring file $WORK/b036/_cgo_main.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x003.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x002.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x004.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x005.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x007.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x008.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x006.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x009.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x010.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x012.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x013.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x014.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x011.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x015.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x016.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x017.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
ld: warning: ignoring file $WORK/b036/_x018.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [android-armv7a] Error 2
I am strugling to solve this as well.
I am trying with gomobile:
CGO_ENABLED=1 \
gomobile bind \
-target=android/arm \
-o export.aar \
-v
I get this:
# gocv.io/x/gocv
ld: error: /usr/local/lib/libopencv_gapi.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_highgui.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_ml.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_objdetect.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_photo.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_stitching.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_video.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_calib3d.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_features2d.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_dnn.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_flann.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_videoio.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_imgcodecs.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_imgproc.so is incompatible with armelf_linux_eabi
ld: error: /usr/local/lib/libopencv_core.so is incompatible with armelf_linux_eabi
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
gomobile: go build -v -buildmode=c-shared -o=/tmp/gomobile-work-3913555039/android/src/main/jniL
ibs/armeabi-v7a/libgojni.so ./gobind failed: exit status 2
I think I need somehow to provide LIBS and CFLAGS to the linker and compiler.
If I set CGO_CPPFLAGS and CGO_LDFLAGS, process kind a moves forward:
export CGO_CPPFLAGS="-I/home/user/engine/gosseract/dependencies/output/armeabi-v7a/lib/sdk/native/jni/include/opencv2"
export CGO_LDFLAGS="-L/home/user/engine/gosseract/dependencies/output/armeabi-v7a/lib/sdk/native/libs/armeabi-v7a -lopencv_core -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn"
Errors:
d: error: undefined symbol: cv::dnn::dnn4_v20210608::readNet(std::__ndk1::basic_string<char, st
d::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, std::__ndk1::basic_string<c
har, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, std::__ndk1::basic_s
tring<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)
>>> referenced by dnn.cpp:4
>>> $WORK/b180/_x021.o:(Net_ReadNet)
ld: error: undefined symbol: cv::dnn::dnn4_v20210608::readNet(std::__ndk1::basic_string<char, st
d::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, std::__ndk1::vector<unsigne
d char, std::__ndk1::allocator<unsigned char> > const&, std::__ndk1::vector<unsigned char, std::
__ndk1::allocator<unsigned char> > const&)
>>> referenced by dnn.cpp:11
>>> $WORK/b180/_x021.o:(Net_ReadNetBytes)