C
C#6mo ago
Brumd

Static linking of `.lib`/`.a` file not working

I'm using Native AOT (+ .NET 8) and I want to statically link my static lib from another language so I can call it from C# while still only distributing a single complete file. It compiles fine but for some reason I keep getting runtime errors of C# looking for a shared object? It says Unhandled exception. System.DllNotFoundException: Unable to load shared library 'mylib' or one of its dependencies C#:
[LibraryImport("mylib", EntryPoint = "load_standard")]
private static partial void LoadStandard();
[LibraryImport("mylib", EntryPoint = "load_standard")]
private static partial void LoadStandard();
CSProj:
<ItemGroup>
<DirectPInvoke Include="mylib" />

<NativeLibrary Include=".\lib\mylib.lib" Condition="$(RuntimeIdentifier.StartsWith('win'))" />
<NativeLibrary Include="./lib/mylib.a" Condition="!$(RuntimeIdentifier.StartsWith('win'))" />
</ItemGroup>
<ItemGroup>
<DirectPInvoke Include="mylib" />

<NativeLibrary Include=".\lib\mylib.lib" Condition="$(RuntimeIdentifier.StartsWith('win'))" />
<NativeLibrary Include="./lib/mylib.a" Condition="!$(RuntimeIdentifier.StartsWith('win'))" />
</ItemGroup>
For context, the file is stored in the lib folder inside project directory. Why is it trying to load the DLL? It's complaining how it can't find mylib.so/libmylib.so/mylib/libmylib, when of course they don't exist because it shouldn't need them? I've been trying to follow various resources like: - https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/interop - https://github.com/dotnet/runtime/issues/89044 - https://github.com/sneusse/aot-static-example
1 Reply
Brumd
BrumdOP6mo ago
nvm, I was using the wrong final executable had to use the one in the bin/Release/net8.0/linux-x64/publish directory
Want results from more Discord servers?
Add your server