5
votes

I have a working Visual Studio project that uses wmain() as the entry-point. I would like to use main() instead.

If I simply change the function signature to int main(), I get:

error LNK2019: unresolved external symbol _wmain referenced in function "void __cdecl mainCRTStartupHelper(struct HINSTANCE__ *,unsigned short const *)"

What option do I need to change to make the link succeed?

2
Project > Properties > General > Character Set - Igor Tandetnik
@IgorTandetnik: This sounded promising. I found it at Configuration Properties > General > Character Set. There are three options: Not Set, Use Unicode Character Set, and Use Multi-Byte Character Set. None of them seem to work. - Brent Bradburn
Actually, I can't reproduce the issue. I've just created a brand new Win32 Console project. I can change freely between main, wmain and _tmain without touching project settings, and the project builds fine. As a very long shot, do you have anything under Linker > Advanced > Entry Point? - Igor Tandetnik
@IgorTandetnik: Your suggestion about the Entry Point was spot on -- I found a solution by messing with that (see my posted answer). I think there is a bit more to it, since it can work with an empty Entry Point (I discovered this by creating a project from scratch as you did). With my existing project, I am not able to use an empty Entry Point (unresolved _WinMain), but at least I have found something that works. --Thanks for the help. - Brent Bradburn
Regarding WinMain vs main: Linker > System > SubSystem. Change from Windows to Console. You want Entry Point to be empty except in certain highly unusual situations. - Igor Tandetnik

2 Answers

1
votes

I found a solution by guessing.

Configuration Properties > Linker > Advanced > Entry Point

was: mainWCRTStartup

now: mainCRTStartup ## removed W

Build succeeded.

0
votes

Insert this pragma in your source file, before int main().

#pragma comment(linker, "/SUBSYSTEM:CONSOLE /ENTRY:mainCRTStartup")

In Visual Studio project configuration, change Character Set to Use Multi-Byte Character Set .