Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple Silicon M1 Pro: Unable to load shared library 'libdl.so' #39

Open
pieterdhondt opened this issue Nov 30, 2021 · 12 comments
Open

Apple Silicon M1 Pro: Unable to load shared library 'libdl.so' #39

pieterdhondt opened this issue Nov 30, 2021 · 12 comments

Comments

@pieterdhondt
Copy link

pieterdhondt commented Nov 30, 2021

Using code:

private async Task<string> GetThumbnailBase64(byte[] imageBytes)
{
       using (var b = new ImageJob())
        {
            var r = await b.Decode(imageBytes)
                .ResizerCommands("width=100&height=100&mode=crop")
                .EncodeToBytes(new MozJpegEncoder(50,true))
                .Finish().InProcessAsync();

            var base64thumbnail = r.First.TryGetBytes().HasValue ? Convert.ToBase64String(r.First.TryGetBytes().Value) : null;
            return base64thumbnail;
        }       
}

I am not able to use the library on a Mac with M1 Pro on macOS 12.0.1.
It throws the following exception:

System.DllNotFoundException: Unable to load shared library 'libdl.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibdl.so, 0x0001): tried: 'liblibdl.so' (no such file), '/usr/local/lib/liblibdl.so' (no such file), '/usr/lib/liblibdl.so' (no such file), '/Users/pieterdhondt/Git/topics-service/TopicsService.Api/liblibdl.so' (no such file), '/usr/local/lib/liblibdl.so' (no such file), '/usr/lib/liblibdl.so' (no such file)
         at Imageflow.Bindings.UnixLoadLibrary.dlopen(String fileName, Int32 flags)
         at Imageflow.Bindings.UnixLoadLibrary.Execute(String fileName)
         at Imageflow.Bindings.NativeLibraryLoader.LoadLibrary(String fullPath, IntPtr& handle, Nullable`1& errorCode)
         at Imageflow.Bindings.NativeLibraryLoader.TryLoadByBasenameInternal(String basename, ILibraryLoadLogger log, IntPtr& handle, IEnumerable`1 customSearchDirectories)
         at Imageflow.Bindings.NativeLibraryLoader.TryLoadByBasename(String basename, ILibraryLoadLogger log, IntPtr& handle, IEnumerable`1 customSearchDirectories)
         at Imageflow.Bindings.NativeLibraryLoader.FixDllNotFoundException[T](String basename, Func`1 invokingOperation, IEnumerable`1 customSearchDirectories)
         at Imageflow.Bindings.JobContextHandle..ctor()
         at Imageflow.Bindings.JobContext..ctor()
         at Imageflow.Fluent.ImageJob.FinishAsync(JobExecutionOptions executionOptions, SecurityOptions securityOptions, CancellationToken cancellationToken)

The same code runs fine on Windows or within a Linux container.

Any advice?

@shane9
Copy link

shane9 commented Jan 2, 2022

internal static class UnixLoadLibrary
{
        // TODO: unsure if this works on Mac OS X; it might be libc instead
        [DllImport("libc.dylib", SetLastError = true, CharSet = CharSet.Ansi)]
        private static extern IntPtr dlopen(string fileName, int flags);
        ...
}

Changing libdl.so to libc.dylib fixes this issue. Then there will be an issue loading libimageflow. Haven't looked into that yet.

I think this would be a good use case for NativeLibrary.SetDllImportResolver

@lilith
Copy link
Member

lilith commented May 14, 2022

What version of .NET are you using? We try to support everything .NET Standard 2.0 does, which means a lot of hackery for every runtime and platform.

@lilith lilith added the bug label May 14, 2022
@shane9
Copy link

shane9 commented May 16, 2022

.NET 6.0 on M1 Mac

@heinzmuller
Copy link

heinzmuller commented Aug 8, 2022

Same issue here, any suggestions @shane9 @pieterdhondt?

@adamshaylor
Copy link

.NET 6.0.400 on M1 for me.

@lilith
Copy link
Member

lilith commented Sep 7, 2022 via email

@lilith
Copy link
Member

lilith commented Sep 29, 2022

Duplicate of imazen/imageflow#592

@lilith lilith marked this as a duplicate of imazen/imageflow#592 Sep 29, 2022
@lilith lilith added enhancement and removed bug labels Sep 29, 2022
@piotr-szczygiel
Copy link

Hi, I have same issue (net7, M2).
Any news about when it will be fixed? It's nearly 2 years since when it was originaly reported.

@lilith
Copy link
Member

lilith commented Jul 4, 2023 via email

@EzzeldenElshrbaty
Copy link

Hi, I have the same issue (net7, M2). any updates????

@lilith
Copy link
Member

lilith commented Nov 26, 2023 via email

@EzzeldenElshrbaty
Copy link

I think it will be a little hard because most of the developers are in different countries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants