-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Using the LD LIBRARY PATH to load local libraries does not work on Linux #34711
Comments
From @sunliusi on Sunday, March 22, 2020 4:28:55 AM NativeLibrary doesn't work either. There are two local libraries, one dependent on the other. This works only if the local library has no dependencies.
---> System.DllNotFoundException: Unable to load shared library 'test.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: ./testaa.so: cannot open shared object file: No such file or directory |
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
From @sunliusi on Wednesday, March 25, 2020 4:29:01 AM Thanks @SourceSkyBoxer for such a detailed explanation. Follow the example above: The problem is that NativeLibrary.Load will fail when file2.so references file1.so. If you put file2.so and file1.so in the root directory, there is no problem |
From @sunliusi on Wednesday, March 25, 2020 4:30:22 AM System.DllNotFoundException: Unable to load shared library '.../unix/file2.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: ./file1.so: cannot open shared object file: No such file or directory |
I believe that |
Related to/possible duplicate of #9529 |
That's correct. And it is not a .NET problem and it is unrelated to propagation env variables settings into the system, setting LD_LIBRARY_PATH has effect only before a process launch for any application written in any language. That's how the dynamic linker works. |
I am running into a similar issue with interop on linux. I have a nuget package that is distributing some native libraries that I am calling with P/Invoke. The libraries are in the bin folder as such:
file1 has a dependency on file2 and file3. The code runs fine on Windows x86 and x64, but fails on linux with this error:
The code is calling into this library as such: [DllImport("file1")
public static extern void NativeMethod(); If I copy the files ldd output without runtimes folder in LD_LIBRARY_PATH
Including runtimes folder in LD_LIBRARY_PATH
|
Put so in the root directory on linux, and put dll in custom directory on windows, it also works. Set LD_LIBRARY_PATH before the program start is not a good idea. It's best to control it using code, just like Windows |
It is my understanding that the /runtimes/[platform]/native folder is supposed to be supported as a delivery mechanism for native libraries https://docs.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders The challenge seems to come in when those libraries have other dependencies also being distributed this way. |
I'm also affected by this problem, and I've spent the past day trying to figure out what is going wrong. Reading this issue I still do not see the best solution (or workaround). Why does .NET not resolve libraries in architecture specific folders (i.e. in |
I have encountered this issue as well and agree with @ssa3512 and @emmenlau that the .NET runtime should be responsible for somehow properly adding all nupkg native libs and their dependencies to the runtime search path. In the meantime, I did find a workaround that I would like to share. You can use the compiler option If you are using CMake then you can add |
From @sunliusi on Sunday, March 22, 2020 4:21:18 AM
I need to use the local library for cross-platform. Local libraries have different implementations and Put them in different folders.
it work fine in windows just like this:
Environment.SetEnvironmentVariable("PATH", path + ";" + Environment.GetEnvironmentVariable("PATH"));
it's not working in linux just like this:
Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", dir + ":" + Environment.GetEnvironmentVariable("LD_LIBRARY_PATH"));
Copied from original issue: dotnet/sdk#10957
The text was updated successfully, but these errors were encountered: