Skip to content

macOS: OpenCvSharpExtern.dylib has hard dependency on @executable_path/../libs instead of runtime-native folder #1797

@D4rxio

Description

@D4rxio

Environment

  • macOS: Apple Silicon (arm64)
  • .NET: net8.0
  • OpenCvSharp4: 4.11.0.20250507
  • Runtime package: OpenCvSharp4.runtime.osx_arm64 (4.8.1)
  • OS: macOS Tahoe 26.2 (25C56) ( arm64)

Problem

On macOS, OpenCvSharpExtern.dylib contains hardcoded runtime dependencies like:
@executable_path/../libs/libfreetype.6.dylib
@executable_path/../libs/libharfbuzz.0.dylib
@executable_path/../libs/libomp.dylib

However, when using the official NuGet runtime package
OpenCvSharp4.runtime.osx_arm64, all native libraries are placed under:

bin/Debug/net8.0/runtimes/osx-arm64/native/
There is no libs/ directory next to the executable by default, so macOS
fails to load OpenCvSharpExtern.dylib at runtime with:

System.DllNotFoundException:
Unable to load shared library ‘OpenCvSharpExtern’

Evidence

Output of:

otool -L runtimes/osx-arm64/native/libOpenCvSharpExtern.dylib
bin/Debug/net8.0/runtimes/osx-arm64/native/libOpenCvSharpExtern.dylib:
        @rpath/libOpenCvSharpExtern.dylib (compatibility version 0.0.0, current version 0.0.0)
        @executable_path/../libs/libfreetype.6.dylib (compatibility version 27.0.0, current version 27.1.0)
        @executable_path/../libs/libharfbuzz.0.dylib (compatibility version 60822.0.0, current version 60822.0.0)
        @executable_path/../libs/libhdf5.310.dylib (compatibility version 313.0.0, current version 313.0.0)
        @executable_path/../libs/libsz.2.0.1.dylib (compatibility version 2.0.0, current version 2.0.1)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
        @executable_path/../libs/libdc1394.26.dylib (compatibility version 27.0.0, current version 27.1.0)
        /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
        /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
        /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
        /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1690.5.4)
        /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
        /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
        /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2299.50.120)
        /System/Library/Frameworks/OpenCL.framework/Versions/A/OpenCL (compatibility version 1.0.0, current version 1.0.0)
        @executable_path/../libs/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1971.0.0)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1971.0.0)
        /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

[
](shows:)
@executable_path/../libs/libfreetype.6.dylib
@executable_path/../libs/libharfbuzz.0.dylib
@executable_path/../libs/libomp.dylib

But these libraries actually exist only in:
runtimes/osx-arm64/native/

Workaround

Manually copying all .dylib files from:
runtimes/osx-arm64/native/

(to:)
bin/Debug/libs/

fixes the issue and OpenCvSharp works correctly.

Expected behavior
	•	Either:
	•	OpenCvSharpExtern.dylib should reference dependencies via @rpath
and include proper LC_RPATH, or
	•	the NuGet runtime package should place dependencies in ../libs
relative to the executable.

Currently the runtime package layout and the dylib rpath assumptions
do not match.

Impact

This breaks:
	•	default dotnet run experience on macOS
	•	Rider / VS debugging on macOS
	•	clean CI builds unless manual copying is done

Linux runtime does not exhibit this issue.

Suggestion

Please consider:
	•	rebuilding OpenCvSharpExtern.dylib with proper @rpath
	•	or aligning NuGet package layout with the hardcoded libs/ path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions