Skip to content

[NativeAOT] How do I link a static library from a nuget package? #108981

Answered by AustinWise
slxdy asked this question in Q&A
Discussion options

You must be logged in to vote

I wrote a sample that statically links the nethost API into NativeAOT app. This sample currently only works when published as NativeAOT. If I get more time, I may extend it support dynamic linking so that it can be run as a normal .NET app on CoreCLR.

https://github.com/AustinWise/DotNetHostingAndNativeAot

Drawing on the sample app, instead of using the Microsoft.NETCore.DotNetAppHost package to get the nethost library, this app finds the nethost library from the targeting pack. Typically the .NET SDK includes this.

I tested this solution on Windows 11, Ubuntu 24.04, and macOS 15. On Linux, you might have to do something like apt-get install libstdc++-dev.

I'll reproduce the current state…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@slxdy
Comment options

@AustinWise
Comment options

@slxdy
Comment options

@slxdy
Comment options

Comment options

You must be logged in to vote
1 reply
@slxdy
Comment options

Answer selected by slxdy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants