C#C
C#2y ago
Virx

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();


CSProj:
<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:
Was this page helpful?