NO

Author Topic: Error of: unresolved external symbol _WinMain@16  (Read 5160 times)

kriss332

  • Guest
Error of: unresolved external symbol _WinMain@16
« on: June 08, 2014, 03:20:48 PM »
Hello to all.
I've been scratching my head since morning (last 8 hours), but of no use, tried all google but couldn't resolve it(I didn't want to post but can't help it now).

I started learning Win API newly and trying to execute following code in a new project (I've tried all 3 types of: win32 application , win32 Program , win32 console). While compiling it gives a warning:
      function 'wmain' can't be __stdcall, changed to __cdel

Then I get error while building:
      Unresolved external symbol '_Winmain@16'
      fatal error: 1 unresolved external(s)

The code is:

Code: [Select]
#include <windows.h>
#include <wchar.h>
int wmain(void)
{
  char *name = "Jane";
  wchar_t *town = L"Bratislava";

  wprintf(L"The length of the name string is %d\n", lstrlenA(name));
  wprintf(L"The town string length is %d\n", lstrlenW(town));

  return 0;
}

Plz guide how to resolve it. I have come from python background. Learnt C 1 yr back & never worked before in this type of IDE. Plz post some kind of instructions also about which type of project to choose for which programs. So that it could help other beginers as well. (I've enabled microsoft extensions, read the help file also.)

Thanks in advance.

neo313

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #1 on: June 09, 2014, 05:48:06 AM »
Try this.

Code: [Select]
#include <windows.h>
#include <wchar.h>

int WINAPI wWinMain(HINSTANCE h , HINSTANCE p , wchar_t* c , int s )
{
  char *name = "Jane";
  wchar_t *town = L"Bratislava";

  wprintf(L"The length of the name string is %d\n", lstrlenA(name));
  wprintf(L"The town string length is %d\n", lstrlenW(town));

  return 0;
}

Relevant:

http://msdn.microsoft.com/en-us/library/windows/desktop/ff381406%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ff381409%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644996%28v=vs.85%29.aspx


kriss332

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #2 on: June 09, 2014, 11:30:32 AM »
Thanks neo, it is working now. But you know, I am following Zetcode tutorials and I tried to follow the convention from there. The code at the end of following link worked(creating the messageBox).
Reference: http://zetcode.com/gui/winapi/main/
But the following link's code that I posted had issue. I am still not sure what is the correct calling convention for that code. There are some entry point differences that I read. If you could clarify that.
Reference: http://zetcode.com/gui/winapi/strings/

I am trying to understand the fundamental difference and procedures of win programming.

Thanks for your time.

laurro

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #3 on: June 09, 2014, 01:33:55 PM »
start a new console project.
copy paste your code in main.c

Code: [Select]
#include <windows.h>
#include <wchar.h>
int wmain(void)
{
  char *name = "Jane";
  wchar_t *town = L"Bratislava";

  wprintf(L"The length of the name string is %d\n", lstrlenA(name));
  wprintf(L"The town string length is %d\n", lstrlenW(town));

  return 0;
}


hit Execute button in toolbar(rebar) second from right
you will get:

Building main.obj.
C:\Program Files\PellesC\Include\Win\winnt.h(559): fatal error #1014: #error: "No target architecture".
*** Error code: 1 ***
Done.

go to
menu/project/project options.../compiler/options
and
enable M$ extensions

hit Execute button again

Laur

kriss332

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #4 on: June 09, 2014, 03:45:55 PM »
Thanks, actually I am working on pelles c compiler on Wine, and it required every time to enable M$ extensions. I didn't pay attention to it yesterday.
One more request- plz let me know the kind of difference when we select difference types of projects. mainly between: win32 application wizard, win32 console program & Win32 program.

Thanks

laurro

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #5 on: June 09, 2014, 09:24:18 PM »
Mainly and most visible is the entry point: main() (wmain()) for console
and WinMain() (wWinMain()) for windows.

Another one is the calling conventions  (only) __cdecl for console apps,
__stdcall and __cdecl for windows apps.

For windows the /Ze option (POCC) enable Microsoft extensions is on by
default, in console is not, you must turn on manually.

Some extra libs in windows user32.lib, gdi32.lib.

   But the most important is /Ze option;

Laur

kriss332

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #6 on: June 10, 2014, 07:41:00 PM »
Thanks alot for that,
One more small question:
How can I get the assembly code of a C program after compiling it using Pelles IDE ?( I've been searching for the answer, but couldn,t get.)


laurro

  • Guest
Re: Error of: unresolved external symbol _WinMain@16
« Reply #7 on: June 10, 2014, 11:13:21 PM »
To "see" the generated code is actually simple, you must run your program under debugger
...project option/
compiler tab/ debug information:full
linker tab/ debug information:CodeView & COFF format

Put a breakpoint in the source code, hit Go/Debug, and when the debugger stop
right click on the break line >show disassembly.

To "dump" the disassembly code ? I don't know how to do that, however in 8
(I still use 7) it seems to be a possibility, see the Timo's addin
http://forum.pellesc.de/index.php?topic=6198.0

Laur

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2097
Re: Error of: unresolved external symbol _WinMain@16
« Reply #8 on: June 11, 2014, 09:27:15 AM »
Using the switch "/Tx86-asm" for 32 bits, or "/Tamd64-asm" for 64 bits the compiler outputs the assembler file instead of object file.
Everything is well documented on IDE help: Menu->help->contents Command line tools.
The help is very complete, but generally nobody read it...  >:(
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide