I have a C# library that exports a function which is then called from Rust.
The problem: The System library is not being linked properly, leading to lots of errors like rust-lld: error: undefined symbol: SystemNative_GetPwUidR.
I've also read that NativeAOT does not support statically linking officially, so I don't really know what to do now.
I think these are my options:
- compile NativeAOT myself and then statically link
- somehow make the generated
.afile not require the system library (and load it at runtime) - not use NativeAOT at all and instead embed a "regular" dotnet runtime into my crate
- build dynamically and then use some sort of self extracting archive to contain the dll/so
note: my experience with csharp/dotnet is really limited.
i just kind of want to make this work.
if there is any information i missed to post, please ask me for it.
also idk if this is the right place to ask this? idk, would a dotnet forum be better?
This is my csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<OutputType>library</OutputType>
<PublishAot>true</PublishAot>
<NativeLib>Static</NativeLib>
</PropertyGroup>
...
This is part of my build.rs:
let out_dir = env::var_os("OUT_DIR")?;
let exit_code = Command::new("dotnet")
.arg("publish")
.arg("csharp")
.arg("-c")
.arg("Release")
.arg("-r")
.arg("linux-x64)
.arg("-o")
.arg(&out_dir)
.arg("-p:NativeLib=Static")
.spawn()?
.wait()?;
// then:
println!("cargo::rustc-link-search=native={}", out_dir.display());
println!("cargo::rustc-link-lib=static=MyLibraryName");
Build output:
error: linking with `cc` failed: exit status: 1
rust-lld: error: undefined symbol: RhpNewPtrArrayFast
>>> referenced by MyLibraryName.o:(S_P_CoreLib_System_UnhandledExceptionEventHandler__InvokeObjectArrayThunk) in archive
target/debug/deps/libunderanalyzer-ffbcf35c47c58571.rlib
>>> referenced 204 more times
and lots more.