dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.97k stars 4.66k forks source link

lots of unresolved symbols in static lib? #103747

Closed ljzj2 closed 2 months ago

ljzj2 commented 2 months ago

Description

I created library in .net 8.0 and compile it to static lib(native aot): dotnet publish -r win-x64 -c release /p:NativeLib=Static and want to use it in c++ program but there is so errors.

Reproduction Steps

  1. create .net 8.0 library
  2. write function [UnmanagedCallersOnly(EntryPoint = "get")] public static IntPtr Get(IntPtr url,){

....... return Intptr.Zero; }

  1. create c++ program and use it

    pragma comment(lib,"mylib.lib")

    extern "C" get (const char* url);

int main(){ auto val=get("this is my href"); }

Expected behavior

will run perfectly

Actual behavior

lots of errors unresolved symbols RhYield RhWaitForPendingFinalizers RhUnregisterForGCReporting RhSuppressFinalize .... NCryptSetProperty NCryptOpenKey NCryptDeleteKey ...... g_cpuFeatures .... GlobalizationNative_ToUnicode GlobalizationNative_LastIndexOf GlobalizationNative_InitICUFunctions

....

as many as over 130 error

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

MichalStrehovsky commented 2 months ago

Additional static libraries are needed to successfully link. Refer to https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary#building-static-libraries, specifically "You can find a list of additional framework libraries by publishing the project as shared library (/p:NativeLib=Shared) with detailed verbosity (-v d), and looking at the output generated by the LinkNative target.".

We do not recommend building static libraries, the developer experience is rough.

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

ljzj2 commented 2 months ago

Ok as you say I will not do that.