dotnet / samples

Sample code referenced by the .NET documentation
https://docs.microsoft.com/samples/browse
Creative Commons Attribution 4.0 International
3.42k stars 5.09k forks source link

nativeaot can not create static lib that c++ can use? #6968

Closed ljzj2 closed 5 months ago

ljzj2 commented 5 months ago

I want to use .net to create library then release it as Static lib(.lib). and another c++ program can use it. I use this: > dotnet publish /p:NativeLib=Static --use-current-runtime int this page https://github.com/dotnet/samples/blob/main/core/nativeaot/NativeLibrary/README.md but it seems not work.

there is one method:

[UnmanagedCallersOnly(EntryPoint = "get")]
public static IntPtr Get(IntPtr url)
{
return IntPtr.Zero
}

yes it will create mylib.lib but nothing in it.

If I use it in c++ program there will be unresolved symbols which means there is no this method in the lib right?

I have used this in c++ #pragma comment(lib,"mylib.lib");