docs
docs copied to clipboard
Trying to build a statically linked binary, getting link error
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.
- ID: 741144e9-61bf-4cb7-c93b-fceb1a5eae71
- Version Independent ID: 22954c29-b82c-5e3d-3bf0-0a954641a341
- Content: Native code interop with Native AOT - .NET
- Content Source: docs/core/deploying/native-aot/interop.md
- Service: dotnet-fundamentals
- GitHub Login: @MichalStrehovsky
- Microsoft Alias: michals
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?
Moving this as a doc improvement issue 🤔