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

SolcLib.Native depends on libc6-dev on linux #1

Closed
fasmat opened this issue Jul 30, 2018 · 5 comments
Closed

SolcLib.Native depends on libc6-dev on linux #1

fasmat opened this issue Jul 30, 2018 · 5 comments

Comments

@fasmat
Copy link

fasmat commented Jul 30, 2018

Hi,

I'm trying to run a small dotnet application using SolcLib.Native inside a docker container. I'm getting the following exception when I'm calling Compile:

System.DllNotFoundException : Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory

The code in question looks like this:

var solclib = SolcLib.Create();
var output = solclib.Compile(pathToSolFile);

I've found a workaround. The dockerfile I use to create my container now looks like this:

FROM microsoft/dotnet:2.1-sdk

# Dependencies for libraries
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       libc6-dev

Would it be possible to get rid of the dependency to not require libc6-dev to be installed to use SolcLib.Native on linux?

@zone117x
Copy link
Member

zone117x commented Jul 30, 2018

With the default SolcNet library interop provider, libdl is used on *nix machines to load the native assembly and to marshal symbols/functions. See here https://github.com/hosho/SolcNet/blob/master/SolcNet/NativeLib/PlatformNativeLibInterop.cs#L33

Could you publish your docker container configuration? I'm not very familiar with the minimum dependencies that linux distros have to ship with, but I'm pretty sure some form of libc (which should include libdl) is required.

Using libdl is a common pattern for cross platform p/invoke in .NET. Examples: https://github.com/search?l=C%23&p=1&q=dllimport+dlopen&type=Code

The SolcNet project actually contains 2 additional native library loaders: NativeLibraryLoader and AdvancedDLSupport. But they are not included in any nuget packages. See them in use and tested here: https://github.com/hosho/SolcNet/blob/master/SolcNet.Test/BindingTests.cs#L14

One difference is that the AdvancedDLSupport provider uses the string constant "dl" rather than "libdl". Perhaps this makes a difference? If you're able to compile SolcNet, you could test by changing it here https://github.com/hosho/SolcNet/blob/master/SolcNet/NativeLib/PlatformNativeLibInterop.cs#L30

If you can give me the configuration of your docker/linux distro I will also do some testing.

@zone117x
Copy link
Member

Also could you run find /usr/lib -name '*libdl*' in the environment without libc6-dev installed, and paste the results?

@zone117x
Copy link
Member

I was able to reproduce this on a fresh Ubuntu Server 18.04 install, did some investigation and implemented a fix.

Linux distros often do not link 'libdl.so' to 'libdl.so.2' by default, and throw that exception when not using the shared lib version naming convention.

Should be fixed in nuget package version 1.1.106. Let me know if that works for you.

@fasmat
Copy link
Author

fasmat commented Jul 31, 2018

Hi @zone117x

The docker container I've been using as a workaround is an extension of the default microsoft dotnet core container. You see it's dockerfile in my original post. I'll try your recent update and give you feedback, if it doesn't work I'll also tell you what the find prints inside my container.

@fasmat
Copy link
Author

fasmat commented Jul 31, 2018

Great! With 1.1.106 and microsoft/dotnet:2.1-sdk I'm not receiving any more errors of missing libraries. Looks like your change worked 👍

@fasmat fasmat closed this as completed Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants