Unable to load shared library OpenCvSharpExtern, Ubuntu 18.04
See original GitHub issueSummary of your issue
When I run any application (with code that runs on Windows) with OpenCvSharp 4, I get an error "System.DllNotFoundException: Unable to load shared library “OpenCvSharpExtern”. I tried to put different versions of packages, but the problem remained. How do I run a project on Ubuntu? I have not found a working solution for this operating system.
Environment
C#, Ubuntu 18.04.4-x64 Installed packages (nuget): OpenCvSharp4 OpenCvSharp4.runtime.ubuntu.18.04-x64
Example code:
class Program
{
static void Main(string[] args)
{
Mat src = new Mat("1.jpg", ImreadModes.Grayscale);
Mat dst = new Mat();
Cv2.Canny(src, dst, 50, 200);
using (new Window("src image", src))
using (new Window("dst image", dst))
{
Cv2.WaitKey();
}
}
}
Output:
Unhandled exception. System.TypeInitializationException: The type initializer for 'OpenCvSharp.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 LD_DEBUG environment variable: libOpenCvSharpExtern: cannot open shared object file: No such file or directory
at OpenCvSharp.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
at OpenCvSharp.ExceptionHandler.RegisterExceptionCallback()
at OpenCvSharp.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
at OpenCvSharp.NativeMethods..cctor()
--- End of inner exception stack trace ---
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:12 (2 by maintainers)
Top Results From Across the Web
'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 >OpenCvSharp.NativeMethods' threw an exception. Unable to ...
[Solved]-'OpenCvSharp.NativeMethods' threw an exception. Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies., Ubuntu 18.04-docker.
Read more >[Solved]-'OpenCvSharp.NativeMethods' threw an exception. Unable ...
NativeMethods' threw an exception. Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies., Ubuntu 18.04-Opencv.
Read more >Where/How do I find missing ffmpeg dependencies?
DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading ...
Read more >Unable to load shared library 'OpenCvSharpExtern' or one ...
Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting ...
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 Free
Top 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
Hello @shimat
I have faced the same issue which was mentioned above “Unable to load shared library OpenCvSharpExtern, Ubuntu 18.04” and I have tried adding all the set of dependencies which you have referenced in the link below: https://github.com/shimat/opencvsharp/blob/master/.github/workflows/ubuntu18.yml#L25
But when I try checking the dependency of the libOpenCvSharpExtern.so using ldd command, I can able to still find some of the dependency is being missed as shown below:
libavcodec.so.57 => not found libavformat.so.57 => not found libavutil.so.55 => not found libswscale.so.4 => not found libjpeg.so.8 => not found
Note: I have installed and checking this assemblies in docker container which is being hosted in Google Kubernetes.
Environment : C#, Ubuntu 18.04.4-x64 Installed packages (nuget): OpenCvSharp4 OpenCvSharp4.runtime.ubuntu.18.04-x64
Kindly let me know your suggestions for the same.
@nietras ,
I figured out a way to get the necessary bits into a docker image without having to build the entire image, with long C++ builds, every time. Maybe this can help you or anyone else on this thread. Unfortunately, I don’t think it is possible to place them in a NuGet package like for Windows because it would require about 800MiB in size for ubuntu 18.04
In the Dockerfile add the following lines
A complete Dockerfile (based on the one generated by Visual Studio) would look like this:
In my case, I built the 4.6 image into a private container registry hence
@shimat , maybe you could have this in the documentation as an alternative to having to build an image from source?