dotnet / LLVMSharp

LLVM bindings for .NET Standard written in C# using ClangSharp
MIT License
838 stars 95 forks source link

libLLVM.so not found #195

Open danielo-unity3d opened 2 years ago

danielo-unity3d commented 2 years ago

The readme says:

A convenience package which provides the native libLLVM library for several platforms is provided here: https://www.nuget.org/packages/libLLVM

But attempting to run the tests (dotnet test in tests/LLVMSharp.UnitTests, running on Ubuntu 20.04) produces:

➜  LLVMSharp.UnitTests git:(main) ✗ dotnet test        
  Determining projects to restore...
  All projects are up-to-date for restore.
  LLVMSharp.Interop -> /home/danielo/Unity/tools/LLVMSharp/artifacts/bin/sources/LLVMSharp.Interop/Debug/net6.0/LLVMSharp.Interop.dll
  LLVMSharp -> /home/danielo/Unity/tools/LLVMSharp/artifacts/bin/sources/LLVMSharp/Debug/net6.0/LLVMSharp.dll
  LLVMSharp.UnitTests -> /home/danielo/Unity/tools/LLVMSharp/artifacts/bin/tests/LLVMSharp.UnitTests/Debug/net6.0/LLVMSharp.UnitTests.dll
Test run for /home/danielo/Unity/tools/LLVMSharp/artifacts/bin/tests/LLVMSharp.UnitTests/Debug/net6.0/LLVMSharp.UnitTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.3.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed CreateDebugLocation [6 ms]
  Error Message:
   System.DllNotFoundException : Unable to load shared library 'libLLVM' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibLLVM: cannot open shared object file: No such file or directory
  Stack Trace:
     at LLVMSharp.Interop.LLVM.ModuleCreateWithName(SByte* ModuleID)
   at LLVMSharp.Interop.LLVMModuleRef.CreateWithName(ReadOnlySpan`1 ModuleID) in /home/danielo/Unity/tools/LLVMSharp/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs:line 94
   at LLVMSharp.Interop.LLVMModuleRef.CreateWithName(String ModuleID) in /home/danielo/Unity/tools/LLVMSharp/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs:line 89
   at LLVMSharp.UnitTests.DIBuilder.CreateDebugLocation() in /home/danielo/Unity/tools/LLVMSharp/tests/LLVMSharp.UnitTests/DIBuilder.cs:line 15
  Failed Intro [< 1 ms]
  Error Message:
   System.DllNotFoundException : Unable to load shared library 'libLLVM' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibLLVM: cannot open shared object file: No such file or directory
  Stack Trace:
     at LLVMSharp.Interop.LLVM.ModuleCreateWithName(SByte* ModuleID)
   at LLVMSharp.Interop.LLVMModuleRef.CreateWithName(ReadOnlySpan`1 ModuleID) in /home/danielo/Unity/tools/LLVMSharp/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs:line 94
   at LLVMSharp.Interop.LLVMModuleRef.CreateWithName(String ModuleID) in /home/danielo/Unity/tools/LLVMSharp/sources/LLVMSharp.Interop/Extensions/LLVMModuleRef.cs:line 89
   at LLVMSharp.UnitTests.Examples.Intro() in /home/danielo/Unity/tools/LLVMSharp/tests/LLVMSharp.UnitTests/Examples.cs:line 17

After performing a restore, where exactly should libLLVM.so be found? (nothing is installed by the restore command)

Note: I installed clang/llvm on my system using sudo apt install clang-12 llvm-12-dev lldb-12

danielo-unity3d commented 2 years ago

Further note: this is fixed with the following command:

$ sudo ln -s /usr/lib/x86_64-linux-gnu/libLLVM-12.so /usr/lib/x86_64-linux-gnu/libLLVM.so

However, I didn't expect to have to install llvm/clang (on the system) in order to be able to use LLVMSharp from a project.

danielo-unity3d commented 2 years ago

What also fixes the problem, is to change libLLVM-11.so to libLLVM-12.so in TryResolveLLVM, but this is also less than ideal.

danielo-unity3d commented 2 years ago

Possibly related: ClangSharp #118