rainyl / opencv_dart

OpenCV bindings for Dart language and Flutter. Support Asynchronous Now!
https://pub.dev/packages/opencv_dart
Apache License 2.0
136 stars 18 forks source link

Support Linux arm64 #263

Closed davidpob99 closed 4 weeks ago

davidpob99 commented 1 month ago

Hi, I would like to ask if aarch64 is going to be supported for Linux or if there is a workaround. It would be very useful for developing for embedded devices.

I tried to build a flutter app with a ARM machine (Ubuntu 20.04) with OpenCV 4.7.0 installed but I got the following error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libopencv_dart.so': libopencv_dart.so: cannot open shared object file: No such file or directory
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
#2      loadNativeLibrary (package:opencv_dart/src/native_lib.dart:37:29)
#3      cimgcodecs (package:opencv_dart/src/native_lib.dart:47:48)
#4      cimgcodecs (package:opencv_dart/src/native_lib.dart)
#5      imread.<anonymous closure>.<anonymous closure> (package:opencv_dart/src/imgcodecs/imgcodecs.dart:29:17)
#6      cvRun (package:opencv_dart/src/core/base.dart:83:76)
#7      imread.<anonymous closure> (package:opencv_dart/src/imgcodecs/imgcodecs.dart:29:5)
#8      cvRunArena (package:opencv_dart/src/core/base.dart:234:31)
#9      imread (package:opencv_dart/src/imgcodecs/imgcodecs.dart:27:10)
#10     main (package:yield_spray/main.dart:18:18)
#11     _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
#12     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Also, I tried to compile the library itself with conan, but I got this error:

======== Input profiles ========
Profile host:
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=gnu14
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux

Profile build:
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=gnu14
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux

======== Computing dependency graph ========
ERROR: conanfile.py (opencv_dart/1.2.5): Error in requirements() method, line 82
        arch = arch_map[platform][str(self.settings.arch)]
        KeyError: 'armv8'

Thanks in advance!

rainyl commented 1 month ago

It's in progress, the stable version, i.e., v1.2.5, doesnt support linux arm64 for now, but i think the branch split-dartcv will work on linux arm64.

Also, conan will be deprecated in the future, i just have no time to update the build instructions.

So, take a look at split-dartcv branch, although it is not finished, it works on linux x64, i didn't test it on linux arm64, if you have any problems, tell me in this issue or in #262

rainyl commented 1 month ago

You need to change the dependency of dartcv at https://github.com/rainyl/opencv_dart/blob/e2eba8204d74697845216b3e8833ea6275569311/packages/opencv_core/pubspec.yaml#L18 to

dartcv:
  path: ../dartcv

I have tried to publish the dartcv package but found there was another package with similar name dart_cv, pub.dev doesn't allow publishing packages with similar names, and I am busy recently, so the dependency was not corrected.

davidpob99 commented 1 month ago

Thank you for you quick response. I followed the instructions and it works in a machine with Ubuntu 22.04. However, in another machine with Ubuntu 20.04 it raises the following error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libdartcv.so': libdartcv.so: undefined symbol: __libc_single_threaded
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
#2      loadNativeLibrary (package:dartcv/src/native_lib.dart:36:29)
#3      cimgcodecs (package:dartcv/src/native_lib.dart:46:48)
#4      cimgcodecs (package:dartcv/src/native_lib.dart)
#5      imread.<anonymous closure>.<anonymous closure> (package:dartcv/src/imgcodecs/imgcodecs.dart:29:17)
#6      cvRun (package:dartcv/src/core/base.dart:83:76)
#7      imread.<anonymous closure> (package:dartcv/src/imgcodecs/imgcodecs.dart:29:5)
#8      cvRunArena (package:dartcv/src/core/base.dart:234:31)
#9      imread (package:dartcv/src/imgcodecs/imgcodecs.dart:27:10)
#10     main (package:yield_spray/main.dart:13:18)
#11     _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
#12     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I searched on the Internet and it seems to be a problem with glibc, in 20.04 the version of that library is < 2.32 (it is 2.31) and the function __libc_single_threaded is not defined.

Maybe is necessary to add that dependency in README?

Refs: https://github.com/wch/r-debug/issues/25, https://stackoverflow.com/questions/76727663/undefined-reference-to-pthread-using-cmake

rainyl commented 1 month ago

@davidpob99 glad it helps.

I searched on the Internet and it seems to be a problem with glibc, in 20.04 the version of that library is < 2.32 (it is 2.31) and the function __libc_single_threaded is not defined.

Yes, the opencv static libs were cross-compiled on ubuntu 22.04, whose libc version was 2.35 (https://ubuntu.pkgs.org/22.04/ubuntu-main-amd64/libc6-dev-arm64-cross_2.35-0ubuntu1cross3_all.deb.html).

Maybe is necessary to add that dependency in README?

Yes, I will add the requirements to README. Thanks~