shimat / opencvsharp

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

libOpenCvSharpExtern.dylib not included in the build #1711

Open Bonfolit opened 1 month ago

Bonfolit commented 1 month ago

Summary of your issue

I am unable to make libOpenCvSharpExtern.dylib to be incuded in my debug build.

Screenshot 2024-10-16 at 16 28 59

I can see it exists in the packages folder, but somehow not included in the build

Screenshot 2024-10-16 at 16 31 07

Environment

Apple M2 Max macOS Ventura 13.5 JetBrains Rider

Installed packages: OpenCvSharp4/4.7.0.20230115 opencvsharp4.runtime.osx.10.15-universal/4.7.0.20230224

What did you do when you faced the problem?

I have tried to force it to be included in my build by editing .csproj manually as below:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
            Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
    <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{637CDC80-B2EA-4C02-AA68-41D345C9ECB1}</ProjectGuid>
        <OutputType>Exe</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <RootNamespace>SiftTest</RootNamespace>
        <AssemblyName>SiftTest</AssemblyName>
        <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
    <RuntimeIdentifiers>osx-arm64;win-x64;win</RuntimeIdentifiers>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
    <RuntimeIdentifiers>osx-arm64;win-x64;win</RuntimeIdentifiers>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="mscorlib" />
        <Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
          <HintPath>..\packages\OpenCvSharp4.4.7.0.20230115\lib\net48\OpenCvSharp.dll</HintPath>
        </Reference>
    <PackageReference Include="OpenCvSharp4.runtime.osx.10.15-universal.4.7.0.20230224"/>
        <Reference Include="System"/>
        <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
          <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
        </Reference>
        <Reference Include="System.Core"/>
        <Reference Include="System.Data"/>
        <Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
          <HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
        </Reference>
        <Reference Include="System.Numerics" />
        <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
          <HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
        </Reference>
        <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
          <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
        </Reference>
        <Reference Include="System.Security" />
        <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
          <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
        </Reference>
        <Reference Include="System.Web" />
        <Reference Include="System.Xml"/>
    </ItemGroup>
    <ItemGroup>
  <None Update="\Users\onurbulbul\RiderProjects\SiftTest\packages\OpenCvSharp4.runtime.osx.10.15-universal.4.7.0.20230224\runtimes\osx-arm64\native\libOpenCvSharpExtern.dylib">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </None>
</ItemGroup>
    <ItemGroup>
        <Compile Include="Program.cs"/>
        <Compile Include="Properties\AssemblyInfo.cs"/>
    </ItemGroup>
    <ItemGroup>
      <None Include="packages.config" />
    </ItemGroup>
    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
    <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
         Other similar extension points exist, see Microsoft.Common.targets.
    <Target Name="BeforeBuild">
    </Target>
    <Target Name="AfterBuild">
    </Target>
    -->

</Project>

Example code:

using OpenCvSharp.Features2D;

namespace SiftTest
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var sift = SIFT.Create();
        }
    }
}

Output:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception. ---> OpenCvSharp.OpenCvSharpException: OpenCvSharpExtern assembly:<unknown assembly> type:<unknown type> member:(null) ---> System.DllNotFoundException: OpenCvSharpExtern assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) OpenCvSharp.Internal.NativeMethods.core_Mat_sizeof()
  at OpenCvSharp.Internal.NativeMethods.TryPInvoke () [0x0000e] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
   --- End of inner exception stack trace ---
  at OpenCvSharp.Internal.NativeMethods.TryPInvoke () [0x0003b] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
  at OpenCvSharp.Internal.NativeMethods..cctor () [0x0003f] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
   --- End of inner exception stack trace ---
  at OpenCvSharp.Features2D.SIFT.Create (System.Int32 nFeatures, System.Int32 nOctaveLayers, System.Double contrastThreshold, System.Double edgeThreshold, System.Double sigma) [0x00000] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
  at SiftTest.Program.Main (System.String[] args) [0x00001] in <99a6f6fe67264acdb6c481b91860c2a5>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception. ---> OpenCvSharp.OpenCvSharpException: OpenCvSharpExtern assembly:<unknown assembly> type:<unknown type> member:(null) ---> System.DllNotFoundException: OpenCvSharpExtern assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) OpenCvSharp.Internal.NativeMethods.core_Mat_sizeof()
  at OpenCvSharp.Internal.NativeMethods.TryPInvoke () [0x0000e] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
   --- End of inner exception stack trace ---
  at OpenCvSharp.Internal.NativeMethods.TryPInvoke () [0x0003b] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
  at OpenCvSharp.Internal.NativeMethods..cctor () [0x0003f] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
   --- End of inner exception stack trace ---
  at OpenCvSharp.Features2D.SIFT.Create (System.Int32 nFeatures, System.Int32 nOctaveLayers, System.Double contrastThreshold, System.Double edgeThreshold, System.Double sigma) [0x00000] in <4e2175a3b7ad402e9ad71963e26dd6c4>:0 
  at SiftTest.Program.Main (System.String[] args) [0x00001] in <99a6f6fe67264acdb6c481b91860c2a5>:0 

Process finished with exit code 1.

What did you intend to be?

Run successfully.

mmolero commented 4 weeks ago

Try use the following packages:

 <PackageReference Include="OpenCvSharp4" Version="4.10.0.20240616" />
 <PackageReference Include="OpenCvSharp4.runtime.osx_arm64" Version="4.8.1-rc" />