shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.39k stars 1.15k forks source link

Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. #701

Closed thebpmgroup closed 3 years ago

thebpmgroup commented 5 years ago

Summary of your issue

Using VSCode and dot net core 2.2 following the instructions :+1:

dotnet new console -n ConsoleApp01 cd ConsoleApp01 dotnet add package OpenCvSharp4 dotnet add package OpenCvSharp4.runtime.ubuntu.18.04-x64

-- edit Program.cs ---

dotnet run

When I add the following code

using System; using OpenCvSharp;

namespace ConsoleApp01 { class Program { static void Main(string[] args) { var srcImage = new Mat(@"/somepathtoafile.jpg"); Cv2.ImShow("Source", srcImage); Cv2.WaitKey(1); // do events } } }

Environment

Ubuntu 18.04 Desktop 64bit

What did you do when you faced the problem?

Just tried to run the program.

Output:

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

Unhandled Exception: System.TypeInitializationException: The type initializer for 'OpenCvSharp.NativeMethods' threw an exception. ---> OpenCvSharp.OpenCvSharpException: 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 ---> 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.core_Mat_sizeof() at OpenCvSharp.NativeMethods.TryPInvoke() in C:\projects\opencvsharp\src\OpenCvSharp\PInvoke\NativeMethods.cs:line 136 --- End of inner exception stack trace --- at OpenCvSharp.NativeMethods.TryPInvoke() in C:\projects\opencvsharp\src\OpenCvSharp\PInvoke\NativeMethods.cs:line 145 at OpenCvSharp.NativeMethods..cctor() in C:\projects\opencvsharp\src\OpenCvSharp\PInvoke\NativeMethods.cs:line 60 --- End of inner exception stack trace --- at OpenCvSharp.NativeMethods.imgcodecs_imread(String filename, Int32 flags) at OpenCvSharp.Mat..ctor(String fileName, ImreadModes flags) in C:\projects\opencvsharp\src\OpenCvSharp\Modules\core\Mat\Mat.cs:line 78 at ConsoleApp01.Program.Main(String[] args) in /home/suityou01/installation/test/ConsoleApp01/Program.cs:line 10

What did you intend to be?

To compile and run ok

8 commented 5 years ago

Hi,

I just had the same problem.

It seems to be a problem with: .nuget\packages\opencvsharp4.runtime.ubuntu.18.04-x64\4.1.0.20190416\runtimes\ubuntu-x64\native\libOpenCvSharpExtern.so which is only 3.5 MB in the release 4.1.0.20190416.

I was able to get it working with an older version, e.g.: 4.0.1.20190326.

where the file: .nuget\packages\opencvsharp4.runtime.ubuntu.18.04-x64\4.0.1.20190326\runtimes\ubuntu-x64\native\libOpenCvSharpExtern.so is 62 MB big

You might wanna downgrade your nuget packages accordingly.

Take care, Martin

SpontaneousDuck commented 5 years ago

Reference #667 to build from source. this worked for me. You need to remove the reference to the runtime package and after everything was built and installed from source it worked for me.

Something must be wrong in the runtime nuget package.

dtjensen commented 5 years ago

I have tried the steps from #667 and still cannot get this to work. I am still facing the issue where the extern lib cannot be loaded. Are there any other approaches to resolve this?

sharpwood commented 4 years ago

I have the same issue on ubuntu 18.04 , OpenCvSharp4.runtime.ubuntu 4.1.1.20191023

shimat commented 4 years ago

Please try checking dependencies of libOpenCvSharpExtern.so

ldd libOpenCvSharpExtern.so
        linux-vdso.so.1 =>  (0x00007ffe441ad000)
        libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007ff98a502000)
        libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007ff98a24d000)
        libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007ff989f39000)
        libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007ff989d17000)
        libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007ff989ac4000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff9897b3000)
        ...

The latest version of libOpenCvSharpExtern.so was made by the Ubuntu18.04 docker container in CircleCI. Please try installing the same packages as it. https://github.com/shimat/opencvsharp/blob/master/.circleci/config.yml

apt -y update
apt -y install wget unzip build-essential checkinstall cmake pkg-config yasm git gfortran libjpeg8-dev libpng-dev software-properties-common
add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
apt -y update && apt -y install libjasper1 libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libv4l-dev
cd /usr/include/linux
ln -s -f ../libv4l1-videodev.h videodev.h
apt -y install libgtk2.0-dev libtbb-dev libatlas-base-dev libvorbis-dev libxvidcore-dev libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils libwebp-dev tesseract-ocr libtesseract-dev libleptonica-dev
sharpwood commented 4 years ago

In the arm64 linux system, Is there any solution to the same problem? @shimat

shimat commented 4 years ago

Sorry, arm64 linux is not supported. (I'm not working on it, but there might be a solution.)

TWhidden commented 4 years ago

+1 for ARM64 -- working on the nvidia nano, want to see if we can use the GPU acceleration for DNN predictions. @shimat , if you want SSH to a device, I can get that info to you. (Ubuntu 18.04 also)

TWhidden commented 4 years ago

Just a follow up -- was able to get Arm64 running - Just simply compile it it --

For those that want what I did, since I used the Nvidia Nano for CUDA acceleration with DNN. Works like a charm!

cd opencv
mkdir release
cd release

cmake   -D WITH_CUDA=ON \
        -D CUDA_ARCH_BIN="5.3,6.2,7.2" \
        -D CUDA_ARCH_PTX="" \
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
        -D WITH_GSTREAMER=ON \
        -D WITH_LIBV4L=ON \
        -D WITH_FFMPEG=ON \
        -D BUILD_TESTS=OFF \
        -D BUILD_PERF_TESTS=OFF \
        -D BUILD_EXAMPLES=OFF \
        -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr/local ..

make -j4
make install
dev-ptdi commented 4 years ago

I am facing the same problem on CentOS 7 x64

[root@iZk1a852gcdx6se03w7daqZ native]# ldd libOpenCvSharpExtern.so linux-vdso.so.1 => (0x00007ffc01dbb000) librt.so.1 => /lib64/librt.so.1 (0x00007fb1f570e000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fb1f54f2000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fb1f52ee000) libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007fb1f50ec000) libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007fb1f4dd6000) libz.so.1 => /lib64/libz.so.1 (0x00007fb1f4bc0000) libm.so.6 => /lib64/libm.so.6 (0x00007fb1f48be000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fb1f45b7000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb1f43a1000) libc.so.6 => /lib64/libc.so.6 (0x00007fb1f3fd3000) /lib64/ld-linux-x86-64.so.2 (0x00007fb1f93f8000) libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fb1f3d71000) [root@iZk1a852gcdx6se03w7daqZ native]#

what I missed or what should I check?

appreciate any help

thanks

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

xwiggen commented 3 years ago

same issue, perhaps a build with ubuntu 20.04 LTS would be nice (ffmpeg libs are newer).

nuurceng commented 1 year ago

~/Desktop/app$ dotnet run Unhandled exception. 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 using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: /usr/lib/dotnet/shared/Microsoft.NETCore.App/7.0.11/OpenCvSharpExtern.so: cannot open shared object file: No such file or directory /usr/lib/dotnet/shared/Microsoft.NETCore.App/7.0.11/libOpenCvSharpExtern.so: cannot open shared object file: No such file or directory /usr/lib/dotnet/shared/Microsoft.NETCore.App/7.0.11/OpenCvSharpExtern: cannot open shared object file: No such file or directory /usr/lib/dotnet/shared/Microsoft.NETCore.App/7.0.11/libOpenCvSharpExtern: cannot open shared object file: No such file or directory

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.imgcodecs_imread(String fileName, Int32 flags, IntPtr& returnValue) at OpenCvSharp.Mat..ctor(String fileName, ImreadModes flags) at App.Program.Main(String[] args)

------------------------------====================------------------------------ How to solve the vscode OpenCvSharp error in Ubuntu?

Ang-Wei-Liang commented 2 months ago

Encountered this issue on apple silicon, solved by changing from dotnet add package OpenCvSharp4.runtime.osx.10.15-x64 --version 4.5.1.20210208 to dotnet add package OpenCvSharp4.runtime.osx_arm64 --version 4.8.1-rc