5

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?

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
  • Project > Properties > General > Character Set – Igor Tandetnik Aug 05 '13 at 21:31
  • 1
    @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 Aug 05 '13 at 21:43
  • 2
    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 Aug 05 '13 at 21:52
  • @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 Aug 05 '13 at 22:01
  • 1
    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 Aug 05 '13 at 22:18
  • Related: http://stackoverflow.com/questions/11785157/replacing-winmain-with-main-function-in-win32-programs – Brent Bradburn Aug 05 '13 at 22:54
  • For the record regarding an earlier comment: "highly unusual situations" are my speciality. :) I think in this case I was targeting (embedded) Windows CE. – Brent Bradburn Mar 23 '15 at 19:03

2 Answers2

1

I found a solution by guessing.

Configuration Properties > Linker > Advanced > Entry Point

was: mainWCRTStartup

now: mainCRTStartup ## removed W

Build succeeded.

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
0

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 .

boleto
  • 1,149
  • 1
  • 22
  • 32
  • This solution is not working. '/ENTRY:mainwCRTStartup' not compatible with switch '/ENTRY:mainCRTStartup'; ignored – kovarex Feb 05 '15 at 10:53