C++ Standard Win32 Console Project Lnker Errors? - by pvdg42

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 454646 Comments
Status Closed Workarounds
Type Bug Repros 7
Opened 5/20/2009 7:58:18 AM
Access Restriction Public


I created a C++ Win32 Empty Console project, then added a .cpp source code file with code as follows:
#include <iostream>

using namespace std;

int main()
	cout << "Hello world from VS 2010!\n";
	return 0;

Results from Rebuild Solution:
Error	1	error LNK2019: unresolved external symbol _wmain referenced in function ___tmainCRTStartup	MSVCRTD.lib(wcrtexe.obj)	VS2010Crash
Error	2	error LNK1120: 1 unresolved externals	D:\2009_Spring_Students\VS2010Crash\Debug\VS2010Crash.exe	VS2010Crash
Sign in to post a comment.
Posted by dvs0826 on 7/7/2009 at 3:48 PM
Hi Lars,

It is not even possible to build a console application with entry point main without setting the character set to MBCS. This has been the same in all versions of Visual Studio. If you want to use entry point main, you must have MBCS. The only difference is apparently that unicode is the default.

Of course, the -real- problem is that Windows uses UTF16 instead of UTF8 :(
Posted by Microsoft on 6/23/2009 at 1:54 PM

Thanks for reporting this issue. We have recognized the issue and have a fix which will be available in the next public release of Visual Studio 2010 (Beta2).

As a workaround for Beta1 you can change the entry point to use "wmain" instead of "main" or change the character set of your project to use "Multi-Byte Character Set"

Project & Build Team
Posted by Lars Viklund on 6/2/2009 at 12:13 PM
In my eyes, this is a horrible regression from earlier versions of Visual Studio.
Why should the standard defined entry point 'main' suddenly not work just because you want the *W Windows API functions to be default.
I strongly hope that this decision is reconsidered, as this currently makes portability very annoying and will cause lots of confusion among beginners.
Setting the solution character set to MBCS is not a solution in my eyes, as that has many deep implications with regard to the Windows API.
Posted by Wolferey on 5/25/2009 at 2:58 AM
yongyi781: Thanks! Is this default now? I have never had this happen in 2008 :o
Posted by yongyi781 on 5/24/2009 at 1:21 PM
Hello, this is NOT an issue with Visual Studio. In Visual C++, the "main" method is "main" in ANSI and "wmain" in Unicode. By default, Visual Studio sets your project to Unicode, so your main function should be renamed "_tmain" (the macro _tmain automatically adjusts to "wmain" or "main" depending on whether the project is set to use Unicode).
Posted by Microsoft on 5/21/2009 at 12:54 AM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team