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

libLLVM isn't working as expected #157

Open
NickStrupat opened this issue Feb 16, 2021 · 4 comments
Open

libLLVM isn't working as expected #157

NickStrupat opened this issue Feb 16, 2021 · 4 comments

Comments

@NickStrupat
Copy link

It's my understanding (could be wrong) that if I don't expect LLVM to be installed on the machine running my program, I should install the libLLVM package so it will output the LLVM library alongside my program.

Assuming that's correct so far, when my csproj is like so:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net5.0</TargetFramework>
	</PropertyGroup>
	
	<ItemGroup>
		<PackageReference Include="LLVMSharp" Version="11.0.0-beta" />
		<PackageReference Include="libLLVM" Version="11.0.0" />
	</ItemGroup>
</Project>

...and my Program.cs is like so:

using LLVMSharp.Interop;
using System;

using var module = LLVMModuleRef.CreateWithName("NativeBinary");

I get this exception, indicating that it can't find the runtime library.

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'libLLVM' or one of its dependencies: The specified module could not be found. (0x8007007E)
  Source=LLVMSharp
  StackTrace:
   at LLVMSharp.Interop.LLVM.ModuleCreateWithName(SByte* ModuleID)
   at LLVMSharp.Interop.LLVMModuleRef.CreateWithName(ReadOnlySpan`1 ModuleID) in /_/sources/LLVMSharp/Interop.Extensions/LLVMModuleRef.cs:line 94
   at LLVMSharp.Interop.LLVMModuleRef.CreateWithName(String ModuleID) in /_/sources/LLVMSharp/Interop.Extensions/LLVMModuleRef.cs:line 89
   at <Program>$.<Main>$(String[] args) in C:\Dev\LLVM-Dotnet-Testing\Program.cs:line 4

The workaround I used is to specify my specific runtime by referencing package libLLVM.runtime.win-x64. While this works, I'd like to be able to build and have it output all the runtimes. Or, build specifically for a runtime with an RID and have it output the necessary libLLVM.

@tannergooding
Copy link
Member

tannergooding commented Feb 16, 2021

This is an issue with NuGet/the runtime as dependencies aren't normally copied to the output folder for non-published builds and so, particularly with the RID specific setup libLLVM has to use, there is no way for the runtime to know where to look for the native dependency.

The easiest workaround today is to add the following to the project since that resolves to a RID and allows the correct native bits for "current machine" to be copied by default:

<PropertyGroup>
    <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

@NickStrupat
Copy link
Author

Oh interesting... so if I specify a RID, I'll get the right libLLVM runtime along with my "published" output? That makes sense.

I guess I assumed NuGet would bring all of them along for the ride until a RID can be determined (by JIT?).

Thanks for you help.

@tannergooding
Copy link
Member

Just noting that I updated the above property to be conditional, since you want to do that so an explicit RID specified on the command line still works.

@donaldnevermore
Copy link
Contributor

I didn't see this, so I had to build LLVMSharp myself and then copied LLVMSharp\artifacts\bin\tests\LLVMSharp.UnitTests\Debug\net5.0\libLLVM.dll to make it work.

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

3 participants