Skip to content

Error loading libdartcv.dylib on macos #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pcrady opened this issue May 25, 2025 · 3 comments
Open

Error loading libdartcv.dylib on macos #358

pcrady opened this issue May 25, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@pcrady
Copy link

pcrady commented May 25, 2025

Describe the bug
On m3 macos I cant find libdartcv.dylib.

(base) petercrady@pcrady-osx example % flutter run -d macos

Launching lib/main.dart on macOS in debug mode...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006031-001A30C92E80011C, name:My Mac }
{ platform:macOS, arch:x86_64, id:00006031-001A30C92E80011C, name:My Mac }
warning: Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this issue, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'DartCvMacOS' from project 'Pods')
Building macOS application...                                           
✓ Built build/macos/Build/Products/Debug/opencv_dart_example.app
flutter: Error loading libdartcv.dylib, error: Invalid argument(s): Failed to load dynamic library 'libdartcv.dylib': dlopen(libdartcv.dylib, 0x0001): tried: 'libdartcv.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibdartcv.dylib' (no such file), '/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_dart/example/build/macos/Build/Products/Debug/opencv_dart_example.app/Contents/Frameworks/FlutterMacOS.framework/Versions/A/./libdartcv.dylib' (no such file), '/usr/local/lib/./libdartcv.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/./libdartcv.dylib' (no such file), '/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_dart/example/build/macos/Build/Products/Debug/opencv_dart_example.app/Contents/Frameworks/FlutterMacOS.framework/Versions/A/../../../libdartcv.dylib' (no such file), '/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_dart/example/build/macos/Build/Products/Debug/opencv_dart_example.app/Contents/MacOS/libdartcv.dylib' (no such file), '/usr/lib/swift/libdartcv.dylib' (no such file, not in dyld cache), '/System/Volumes/Preboot/Cryptexes/OS/usr/lib/swift/libdartcv.dylib' (no such file), '/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_dart/example/build/macos/Build/Products/Debug/opencv_dart_example.app/Contents/Frameworks/libdartcv.dylib' (no such file), '/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_dart/example/build/macos/Build/Products/Debug/opencv_dart_example.app/Contents/MacOS/Frameworks/libdartcv.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libdartcv.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libdartcv.dylib' (no such file), '/usr/lib/libdartcv.dylib' (no such file, not in dyld cache), 'libdartcv.dylib' (no such file)
fallback to process.
Syncing files to device macOS...                                    26ms

This is for the example project:

/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_dart/example
(base) petercrady@pcrady-osx example % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.0, on macOS 15.5 24F74 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 16.3)
    ! CocoaPods 1.15.2 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.

To Reproduce
Try to run the example project on an M series mac.

@pcrady pcrady added the bug Something isn't working label May 25, 2025
@pcrady
Copy link
Author

pcrady commented May 25, 2025

I updated cocoapods and got the same issue:

(base) petercrady@pcrady-osx example % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.0, on macOS 15.5 24F74 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

@pcrady pcrady changed the title Error loading libdartcv.dylib Error loading libdartcv.dylib on macos May 25, 2025
@pcrady
Copy link
Author

pcrady commented May 25, 2025

I did eventually get it working with great difficulty. For the opencv_core example:

/Users/petercrady/StudioProjects/opencv_dart/packages/opencv_core/example

First i had to make a build directory inside example:

mkdir build

Then I went to /Users/petercrady/StudioProjects/opencv_dart/packages/opencv_core/src and ran:

cmake .
make

I then found all the dylibs and copied them into the ephemeral build directory:

(base) petercrady@pcrady-osx src % cp $(find . | grep dylib) /Users/petercrady/StudioProjects/opencv_dart/packages/opencv_core/example/build/macos/Build/Products/Debug/opencv_core_example.app/Contents/MacOS/

I then went to that directory and had to codesign all of the files:

codesign --force --sign - *

and then i was able to run the example app with no errors. This obviously isnt great since that directory will be deleted if you do flutter clean.

Sorry to bother you with all this. I'm in way over my head with the C code so i have no idea what i'm doing.

@rainyl
Copy link
Owner

rainyl commented May 26, 2025

@pcrady Well, maybe I should apologize for the misleading exception message.

TL;DR, actually it works as expected, you do not need to build and copy it manually.

For macos, in order to support pure dart and Flutter, the dynamic library searching will firstly try to load libdartcv.dylib (for pure dart) and then fallback to load from process (for Flutter), therefore you can see the message fallback to process. (since the C codes will be built automatically and flutter will package it to a .framework).

I will change the error message to a warning when having some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants