I’m trying to test this static linking example with .net in linux and keep getting the following exception;
System.DllNotFoundException: Unable to load shared library 'nativelib' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/workspaces/Test/app/bin/Debug/net8.0/linux-x64/nativelib.so: cannot open shared object file: No such file or directory
/workspaces/Test/app/bin/Debug/net8.0/linux-x64/libnativelib.so: cannot open shared object file: No such file or directory
/workspaces/Test/app/bin/Debug/net8.0/linux-x64/nativelib: cannot open shared object file: No such file or directory
/workspaces/Test/app/bin/Debug/net8.0/linux-x64/libnativelib: cannot open shared object file: No such file or directory
The .csproj links the .a lib as follows. I’ve added the nativelib.a lib to the /app folder for easy access.
<ItemGroup>
<!-- Generate direct PInvokes for Dependency -->
<DirectPInvoke Include="nativelib" />
<NativeLibrary Include="nativelib.a" />
</ItemGroup>
The project builds and compiles but when I run it, I get this error. I suspect that it’s because it treats the lib as a dynamic dll/.so instead of a static lib.
How do I fix this? Any help would be appreciated.