添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

'OpenCvSharp.NativeMethods' threw an exception. Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies., Ubuntu 18.04

Ask Question

I have used the OpenCvSharp library in my .net core 3.0 application when running this application in the windows environment, the application is running without any issues. When the same application is deployed and hosted in the docker running in ubuntu 18.04 the following exception is occurred:

System.DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies.

I have installed the following packages (nuget) which are required for running the OpenCvSharp4 in the ubuntu environment:

  • OpenCvSharp4
  • OpenCvSharp4.runtime.ubuntu.18.04-x64
  • When Checked the dependency of the libOpenCvSharpExtern.so library using the following command:

    ldd libOpenCvSharpExtern.so
    

    Some of the dependency assemblies was missing, so I have installed all the necessary packages which is mentioned in the below GitHub thread which reports the same exact issue:

    https://github.com/shimat/opencvsharp/issues/889

    But still the some of the dependencies are found to be missing and those assemblies name are given 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
  • I have also tried installing the following packages “libjpeg62-turbo-dev” and “libavcodec-extra57” for fixing the ‘not found’ assemblies. But still the issue occurred.

    Any suggestion on how to fix this issue would be appreciated.

    @HannesSachsenhofer have you managed to solve this...? Would be grateful if there was an answer to this. – alexts Mar 6, 2021 at 22:18

    We had the same issue. After a lot of experimentation we got it working with the following setup (Docker):

    csproj

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="OpenCvSharp4" Version="4.4.0.20200725" />
        <PackageReference Include="OpenCvSharp4.runtime.debian.10-amd64" Version="4.3.0.20200424" />
        <PackageReference Include="OpenCvSharp4.runtime.win" Version="4.4.0.20200725" />
        <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
      </ItemGroup>
    </Project>
    

    dockerfile

    [...]
    FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
    [...]
    RUN apt-get update && apt-get install -y \
        apt-utils \
        libgdiplus \
        libc6-dev \
        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 \
        libtiff-dev \
        libavcodec-dev \
        libavformat-dev \
        libswscale-dev \
        libdc1394-22-dev \
        libxine2-dev \
        libv4l-dev
    RUN apt-get clean && rm -rf /var/lib/apt/lists/*
    [...]
    

    Unfortunately, I'm not entirely sure which of the many apt packages did the trick, I'm just happy it works now ;)

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.