opencvsharp: Unable to load shared library OpenCvSharpExtern, Ubuntu 22.04
Summary of your issue
I’m trying OpenCvSharp on Ubuntu 22.04 and I’m getting following error
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
I’m referencing OpenCvSharp4.runtime.ubuntu.18.04-x64 package.
Environment
Ubuntu 22.04
What did you do when you faced the problem?
libOpenCvSharpExtern is located in build folder under ./bin/Debug/net6.0/runtimes/ubuntu.18.04-x64/native/ instead ./bin/Debug/net6.0/. So running ldd libOpenCvSharpExtern.so returns shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
Then I copied libOpenCvSharpExtern.so to ./bin/Debug/net6.0/ and try to run application from there resulting in same : 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 exception.
Then I run ldd libOpenCvSharpExtern.so again resulting in :
❯ ldd libOpenCvSharpExtern.so
linux-vdso.so.1 (0x00007ffc407f8000)
libtesseract.so.4 => /lib/x86_64-linux-gnu/libtesseract.so.4 (0x00007f5be46f6000)
libgtk-x11-2.0.so.0 => /lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007f5be427f000)
libgdk-x11-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007f5be89f9000)
libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f5be4157000)
libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f5be89c9000)
libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f5be8967000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f5be401d000)
libdc1394.so.22 => not found
libavcodec.so.57 => not found
libavformat.so.57 => not found
libavutil.so.55 => not found
libswscale.so.4 => not found
libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f5be3f9c000)
......
So, I have few questions like:
- can we have proper Ubuntu 22.04 nuget package ?
- list of required Ubuntu packages that we need to install before using OpenCvSharp ?
- fix deploy script so we have
libOpenCvSharpExtern.soin proper location ?
I would like to use OpenCvSharp but this is blocking me for using it.
Example code:
byte[] image = new ();// not important
Mat src = Cv2.ImDecode( image, ImreadModes.Color );
Output:
Error Message:
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 LD_DEBUG environment variable: libOpenCvSharpExtern: cannot open shared object file: No such file or directory
What did you intend to be?
Compile and run.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (4 by maintainers)
Here’s the code @dsoronda
It’s just taking the existing Dockerfile and adding a step to build a NuGet package.
package.zip
One can then create the package by:
However, concerning Jammy.Dockerfile, I’m just guessing the needed native deps. But the tests are passing and the OpenCV functionality I need in my project seems to work as well.
@Evelios How far did you get?
I’ve made two NuGet packages for internal use that contain binaries for Ubuntu 20.04 and Ubuntu 22.04. I’m now working on dockerizing the creation of both. I could then turn that into a PR, would you be interested?
For anyone who wants to use 4.7.0 that was released last month, @shimat has already created a dockerfile for building
libOpenCvSharpExtern.sounder Ubuntu 22.04, so we can build it from scratchWait for it to complete then
cd export/artifacts, finally you should be able to see thelibOpenCvSharpExtern.so.Before using it for your .NET application, you should check out if there are sufficient dependencies had been installed on your environment(out of the building system Ubuntu 22.04 in the docker container):
and install any(not need to install all of them in
dockerfile) missing packages to fix these missing dependencies: https://github.com/shimat/opencvsharp/blob/7ed8972de415fad623d425e56b4f87ef2503d68b/docker/ubuntu22-dotnet6-opencv4.7.0/Dockerfile#L9-L34If you want to use a more recent version of Tesseract(
libtesseract-devfrom the default source is still in4.1.1, and the latest is5.3.0), replace the line 9 ofDockerfilehttps://github.com/shimat/opencvsharp/blob/7ed8972de415fad623d425e56b4f87ef2503d68b/docker/ubuntu22-dotnet6-opencv4.7.0/Dockerfile#L9 with@lewispurvis if you manage to make these two packages part of the general release procedure, it’d be really great! I’d much rather use these, than my privately maintained ones. I can share the code for building the packages, if you’re interested.
I have been trying to get a solution to this one too. I’ve been following through the steps in the github workflows and am in the process of trying to get it compiled on Ubuntu 22.04 but I’m getting stuck as well.
I am working on a pull request to allow them to publish this runtime package.
A brief rundown of where I’m at, I added .github/workflows/ubuntu22.yml with the following changes
ubuntu-22.04fromubuntu-22.04libswresample-devused instead of the deprecated packagelibawresample-devlibdc1394-devused instead of the deprecatedlibdc1394-22-devAt this point I’m out of ideas on what to run next. I’m running into issues of the
libavresample.sopackage which is not currently built for Ubuntu 22 Jelly Jam and the replacement that I thought could be a good alternativelibswresample-devapparently isn’t quite the right fit for a quick swap which doesn’t seem to be the caseI also found this stack overflow about the difference between
avresampleandswresample.