Created
March 8, 2023 03:49
-
-
Save jkotas/f70c77015f24b31f00ca37ac67f388fa to your computer and use it in GitHub Desktop.
Native AOT static linking demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net7.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |
<PublishAot>true</PublishAot> | |
</PropertyGroup> | |
<ItemGroup> | |
<NativeLibrary Include="mylibrary.obj" /> | |
<DirectPInvoke Include="mylibrary" /> | |
</ItemGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern int MyMethod(); | |
int MyMethod() | |
{ | |
return 42; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
partial class Program | |
{ | |
static void Main() => Console.WriteLine(MyMethod()); | |
[LibraryImport("MyLibrary")] | |
private static partial int MyMethod(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment