-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NativeAOT: support for building static libraries for Debug CRT on Windows #98356
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsI would like to use NativeAOT to create a static library that I then link into a larger C/C++ project on Windows. The C/C++ project has a debug configuration and a release configuration. In the debug configuration, the project links against the debug version of the C runtime. In the release configuration, it uses the release C runtime. The static library that NativeAOT produces links against runtime/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets Lines 103 to 107 in f4f9bd5
this is somewhat possible to change by doing some custom targets that mess with the Unfortunately, that's not enough. The reason is because the assorted helper libraries such as It would be nice if the NativeAOT build integration provided versions of these libraries linked against the debug CRT.
|
Sample of what I'm doing: https://github.com/lambdageek/naothello Note: I don't think we want the support libraries to be built in the Debug configuration - we release builds of the libraries, as usual, we just want them to link against the debug CRT |
This comment was marked as outdated.
This comment was marked as outdated.
No, I was wrong. it's not working.
|
What happens if you ignore this warning? |
The app runs. But I'm not familiar enough with Windows development to tell if that's just an accident because my native code is a toy (so it doesn't touch enough of the CRT to get into trouble) or if everything is ok. |
Everything should be ok. NativeAOT does not use C++ STL where mixing debug and release would get you into trouble. You should be able to use |
@jkotas just to double check. The warning is coming from the point where I'm linking the NativeAOT artifacts together with my C code. if I use On the other hand adding this is the link step (without any
|
Release The easiest way to find out what is going on is to open |
This is built upon |
Thanks! I ended up using Adding your suggested |
Nope, still blocked. If I change my native hosting app to C++ things break due to the
The app is in the The app's own code gets these directives:
And the linker complains (one example of about 120):
I see no way to tell the linker to ignore |
Hmm, I guess the only way to solve these sorts of scenarios in scalable way would be to ship the runtime sources in the package and allow the user to compile them with any options they want. We do that for ICU and OpenSSL shims today: https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#using-statically-linked-icu |
We track the build from source scenario here: #83611 It's not just the debug/release mismatch. There could also be ABI differences, we were just lucky that MSVC hasn't done a breaking change in ABI recently. Building static libraries out of native AOT is not recommended. I think this issue should just track adding "we really don't recommend you to do this" to the dotnet/samples sample. I never really liked we soft-documented this by adding the static library case to the dotnet/samples sample. |
I would like to use NativeAOT to create a static library that I then link into a larger C/C++ project on Windows.
The C/C++ project has a debug configuration and a release configuration. In the debug configuration, the project links against the debug version of the C runtime. In the release configuration, it uses the release C runtime.
The static library that NativeAOT produces links against
ucrt.lib
:runtime/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
Lines 103 to 107 in f4f9bd5
this is somewhat possible to change by doing some custom targets that mess with the
LinkerArg
item group after theSetupOSSpecificProps
target.Unfortunately, that's not enough. The reason is because the assorted helper libraries such as
bootstrapperdll.obj
,eventpipe-disabled.lib
,Runtime.WorkstationGC.lib
etc are all compiled with the release CRT, so you get linker errors when including them into a native app in Release mode.It would be nice if the NativeAOT build integration provided versions of these libraries linked against the debug CRT.
The text was updated successfully, but these errors were encountered: