Unresolved external symbol _WinMain@16
I got this error message today:
msvcrt.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
The most common cause for this error message is adding Unicode configurations to your project and forgetting to change the entry point to
wWinMainCRTStartup. See this Microsoft KB article (or my article) for more information.
This wasn’t my problem: I’d already done that.
The puzzling thing was that the error was intermittent: I’d get it when building the project as part of a batch build; then I wouldn’t; then it’d keep happening if I built the project on its own. I’d clean the project, and then it’d work. Then if I did a batch build, the problem would come back again.
It turns out that when you create a new configuration, and base it on an existing one – I created the “Debug Unicode” configuration, and based it on the “Debug” configuration – Visual Studio doesn’t always correctly update all of the paths in the project settings. This means that the “Debug” and “Debug Unicode” configurations were sharing precompiled headers, debug information and other stuff. No wonder the linker was getting confused.
Admittedly, Visual Studio.NET’s confusion could be due to me importing the project from a Visual Studio 6 project.
To fix it, you need to change the following entries, so that they have the correct paths in – or you can specify
- General / Output Directory: This sets
$(OutDir). You should probably set it to
- General / Intermediate Directory: This sets
$(IntDir). You should probably set it to
- C/C++ / Precompiled Headers / Precompiled Header File: You should set this to
- C/C++ / Output Files / Object File Name: Set this to
- C/C++ / Output Files / Program Database File Name: Set this to
- Linker / General / Output File:
- Linker / Debugging / Generate Program Database File:
- Resources / Additional Include Directories:
- Resources / Resource File Name:
There might be other places you need to check, e.g. depending on whether you’ve got browser information turned on.