MacOS Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies.
See original GitHub issueMacOS Unable to load shared library ‘OpenCvSharpExtern’ or one of its dependencies.
Environment
macOS Big Sur 11.6.1
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.osx.10.15-x64" Version="4.5.5.20211231" />
What did you do when you faced the problem?
- Copied
libOpenCvSharpExtern.dylib
fromruntimes/osx-x64/native
tobin/debug/net5.0
. - Installed required dependencies manually:
brew install wget pkg-config mono-libgdiplus gtk+ ffmpeg glog yasm harfbuzz jpeg libpng libtiff openjpeg metis openblas opencore-amr protobuf tbb webp
Output:
Warning: wget 1.21.2 is already installed and up-to-date.
To reinstall 1.21.2, run:
brew reinstall wget
Warning: pkg-config 0.29.2_3 is already installed and up-to-date.
To reinstall 0.29.2_3, run:
brew reinstall pkg-config
Warning: mono-libgdiplus 6.1 is already installed and up-to-date.
To reinstall 6.1, run:
brew reinstall mono-libgdiplus
Warning: gtk+ 2.24.33 is already installed and up-to-date.
To reinstall 2.24.33, run:
brew reinstall gtk+
Warning: ffmpeg 4.4.1_5 is already installed and up-to-date.
To reinstall 4.4.1_5, run:
brew reinstall ffmpeg
Warning: glog 0.5.0 is already installed and up-to-date.
To reinstall 0.5.0, run:
brew reinstall glog
Warning: yasm 1.3.0_2 is already installed and up-to-date.
To reinstall 1.3.0_2, run:
brew reinstall yasm
Warning: harfbuzz 3.2.0 is already installed and up-to-date.
To reinstall 3.2.0, run:
brew reinstall harfbuzz
Warning: jpeg 9e is already installed and up-to-date.
To reinstall 9e, run:
brew reinstall jpeg
Warning: libpng 1.6.37 is already installed and up-to-date.
To reinstall 1.6.37, run:
brew reinstall libpng
Warning: libtiff 4.3.0 is already installed and up-to-date.
To reinstall 4.3.0, run:
brew reinstall libtiff
Warning: openjpeg 2.4.0 is already installed and up-to-date.
To reinstall 2.4.0, run:
brew reinstall openjpeg
Warning: metis 5.1.0 is already installed and up-to-date.
To reinstall 5.1.0, run:
brew reinstall metis
Warning: openblas 0.3.19 is already installed and up-to-date.
To reinstall 0.3.19, run:
brew reinstall openblas
Warning: opencore-amr 0.1.5 is already installed and up-to-date.
To reinstall 0.1.5, run:
brew reinstall opencore-amr
Warning: protobuf 3.19.3 is already installed and up-to-date.
To reinstall 3.19.3, run:
brew reinstall protobuf
Warning: tbb 2021.5.0 is already installed and up-to-date.
To reinstall 2021.5.0, run:
brew reinstall tbb
Warning: webp 1.2.2 is already installed and up-to-date.
To reinstall 1.2.2, run:
brew reinstall webp
- Checked dependencies for
libOpenCvSharpExtern.dylib
, everything is available.
otool -L libOpenCvSharpExtern.dylib
Output
libOpenCvSharpExtern.dylib:
@rpath/libOpenCvSharpExtern.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/opt/freetype/lib/libfreetype.6.dylib (compatibility version 25.0.0, current version 25.1.0)
/usr/local/opt/harfbuzz/lib/libharfbuzz.0.dylib (compatibility version 30200.0.0, current version 30200.0.0)
/usr/local/opt/tesseract/lib/libtesseract.4.dylib (compatibility version 5.0.0, current version 5.1.0)
/usr/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 9.0.0)
/usr/local/opt/ffmpeg/lib/libavcodec.58.dylib (compatibility version 58.0.0, current version 58.134.100)
/usr/local/opt/ffmpeg/lib/libavformat.58.dylib (compatibility version 58.0.0, current version 58.76.100)
/usr/local/opt/ffmpeg/lib/libavutil.56.dylib (compatibility version 56.0.0, current version 56.70.100)
/usr/local/opt/ffmpeg/lib/libswscale.5.dylib (compatibility version 5.0.0, current version 5.9.100)
/usr/local/opt/ffmpeg/lib/libavresample.4.dylib (compatibility version 4.0.0, current version 4.0.0)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1463.2.1)
/System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2022.20.117)
/System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 904.4.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.255.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1770.255.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
- Ensured project is running under 64 bit architecture:
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
- Installed opencv via Homebrew.
- Looked into other closed issues, did not find solution to my problem.
Example code:
Console.WriteLine(Cv2.GetVersionString());
Output:
System.TypeInitializationException: The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.
---> System.DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libOpenCvSharpExtern, 1): image not found
at OpenCvSharp.Internal.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
at OpenCvSharp.Internal.ExceptionHandler.RegisterExceptionCallback()
at OpenCvSharp.Internal.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
at OpenCvSharp.Internal.NativeMethods..cctor()
--- End of inner exception stack trace ---
at OpenCvSharp.Internal.NativeMethods.core_getVersionString(Byte* buf, Int32 maxLength)
at OpenCvSharp.Cv2.GetVersionString()
What did you intend to be?
Library works and outputs version correctly.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
MacOS runtime error (Unable to load shared library ' ...
"Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting ...
Read more >Unable to load shared library 'OpenCvSharpExtern' VS for ...
In short: the only workaround I've found is to build OpenCV and OpenCVSharpExtern right inside your container. Works quite well.
Read more >'OpenCvSharp.NativeMethods' threw an exception. Unable ...
'OpenCvSharp.NativeMethods' threw an exception. Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies., Ubuntu 18.04.
Read more >MacOS runtime error (Unable to load shared library ' ...
I get Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies constantly while trying to create Mat object.
Read more >opencvsharp
Native binding (OpenCvSharpExtern.dll / libOpenCvSharpExtern.so) is required to work OpenCvSharp. To use OpenCvSharp, you should add both OpenCvSharp4 and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As @obie73 said, the OpenCvSharp of version
4.5.5.2021.1213
is not compatible with the installedffmpeg
version 5.x.x. It has to installffmpeg
with version 4.x.x.There is a cue from loading
libOpenCvSharpExtern.dylib
test.After
brew install ffmpeg@4
, it works out. (Remember link such asln -s /usr/local/Cellar/ffmpeg@4/4.4.2_3/ /usr/local/opt/ffmpeg
)I was getting this problem and one of the errors referred to: could not find /usr/local/opt/tesseract/lib/tesseract.5.dylib I did a homebrew install of tesseract
brew install tesseract
and now it works. Only working on a AMD64 (x64) Mac and tested on Monterey and building within “Visual Studio for Mac”FYI: https://www.oreilly.com/library/view/building-computer-vision/9781838644673/95de5b35-436b-4668-8ca2-44970a6e2924.xhtml