question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load shared library OpenCvSharpExtern, Ubuntu 22.04

See original GitHub issue

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.so in 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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
lejsektcommented, Nov 1, 2022

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:

docker buildx build -f Focal.Dockerfile . -o export
docker buildx build -f Jammy.Dockerfile . -o export

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.

3reactions
lejsektcommented, Oct 7, 2022

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load shared library OpenCvSharpExtern, Ubuntu ...
When I run any application (with code that runs on Windows) with OpenCvSharp 4, I get an error "System.DllNotFoundException: Unable to load ......
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 >
Upgrading to Ubuntu 22.04 causes libcrypto errors, apt ...
1.1: cannot open shared object file: No such file or directory , I inferred that a library may be missing. As per this...
Read more >
opencvsharp
To use OpenCvSharp, you should add both OpenCvSharp4 and OpenCvSharp4.runtime.* packages to your project. Currently, native bindings for Windows, UWP and Ubuntu ......
Read more >
Docker multi-architecture, .NET 6.0 and OpenCVSharp
The objective of this post is to build a reusable multi-architecture Docker image containing native OpenCVSharpExtern library as well as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found