Closed ShackGH closed 6 months ago
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.
I think you're confused -- dotnet run
does not use Native AOT.
My apologies, this is the first time I'm trying Native AOT. I tried running it with ./bin/Release/net8.0/linux-x64/publish/demo
and got a similar error
Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'MyLibrary' 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:
MyLibrary.so: cannot open shared object file: No such file or directory
libMyLibrary.so: cannot open shared object file: No such file or directory
MyLibrary: cannot open shared object file: No such file or directory
libMyLibrary: cannot open shared object file: No such file or directory
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x127
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Program.MyMethod() + 0x1f
at demo!<BaseAddress>+0xd6ca4
Given the error, it doesn't look like your library is statically linked. How did you build the native library? And can you provide an dotnet binlog (add -bl
to your publish command)?
Did you specify the DirectPInvoke
in project file correctly in the same lower/upper case as in the DllImport/LibraryImport
attributes?
@agocke I use dotnet publish -r linux-x64 -c Release
to build it. The .o is built with gcc -c mylibrary.c -o mylibrary.o
.
Added the binlog
msbuild.zip
I'm using vscode docker .net image for the project
@filipnavara The .csproj is the same as specified in the example link except for the changes I mentioned.
<ItemGroup>
<NativeLibrary Include="mylibrary.o" />
<DirectPInvoke Include="mylibrary" />
</ItemGroup>
Try changing LibraryImport("MyLibrary")
in the source file to LibraryImport("mylibrary")
.
@filipnavara , you were correct... I was convinced that it wasn't working with linux, thanks!
I'm trying to test this example in linux. Changed
<TargetFramework>
tonet8.0
andmylibrary.obj
tomylibrary.o
in demo.csprojdotnet publish -r linux-x64 -c Release
works without issue but when I try to run in withdotnet run
it gives the following error;Looks like the static link is being ignored?