dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.29k stars 5.92k forks source link

Trying to build a statically linked binary, getting link error #40680

Open JackHarckness opened 7 months ago

JackHarckness commented 7 months ago

The problem

I was trying to build a statically linked binary that Direct P/Invokes into a static dependency according to an official doc, got error LNK2001: unresolved external symbol while trying to do so. I then referred to an existing working example, tried to build it but got the same error. I've also tried to run the build command from a Developer Command Prompt for VS, still the same error. Command where link && where cl returns two paths pointing to msvc linker and compiler accordingly, so the absence of these is clearly not an issue.

To Reproduce

On Windows, invoke build.bat from https://github.com/sneusse/aot-static-example


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

JackHarckness commented 7 months ago

Actually running build.bat from x64 Native Tools Command Prompt for VS 2022 solved the issue and got comilation going. I guess there is an issue within my specific configuration, maybe something is wrong with PATH. Perhaps we should consider extending the doc, since this is not an obvious solution?

nagilson commented 7 months ago

Moving this as a doc improvement issue 🤔