Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » undefined reference to `WinMain@16'
undefined reference to `WinMain@16' [message #211325] Sat, 08 March 2008 04:01 Go to next message
Eclipse UserFriend
Originally posted by: malekm.centrum.cz

Hi,
I tried CDT instead VS, because i use Eclipse for java programming.

But if I test compile windows program, it appear error "undefined
reference to `WinMain@16'". Compiling console app is ok. I searched all
this forum and all links from Google, but nothing help me.

Here is simple example:

#include "windows.h"

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine,
int nShowCmd)
{
MessageBox(NULL, TEXT("Ahoj svete!"), TEXT("Muj pokus"), MB_OK);
return 0;
}

Console list:
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\AhojSvete.o
..\src\AhojSvete.cpp
..\src\AhojSvete.cpp:7:2: warning: no newline at end of file
g++ -oAhojSvete.exe src\AhojSvete.o
/mingw/lib/libmingw32.a(main.o):main.c:(.text+0x104): undefined reference
to `WinMain@16'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 2172 ms.

Running on Eclipse 3.3.1.1, CDT 4.0.3, MinGW-5.1.3, MSYS-1.0.10

Thanks for your help.
Re: undefined reference to `WinMain@16' [message #211354 is a reply to message #211325] Sat, 08 March 2008 15:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: labmonkey42.gmail.com

You need to add "-mwindows" to your linker flags.
unrecognised emulation mode: windows [message #211361 is a reply to message #211354] Sat, 08 March 2008 16:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: malekm.centrum.cz

Thanks, I tried this before, but I added it on wrong place.

Now the console look:

**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\AhojSvete.o
..\src\AhojSvete.cpp
..\src\AhojSvete.cpp:7:2: warning: no newline at end of file
g++ -Xlinker -mwindows -oAhojSvete.exe src\AhojSvete.o
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bi n\ld.exe:
unrecognised emulation mode: windows
Supported emulations: i386pe
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 4891 ms.


So what mean "unrecognised emulation mode: windows" and when I can change
emulation mode?

Thx

M
Re: unrecognised emulation mode: windows [message #211372 is a reply to message #211361] Sat, 08 March 2008 23:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: labmonkey42.gmail.com

I'm not 100% sure, but I think every time I've built a win32 api with
mingw I linked with gcc (even if the objects were compiled with g++).
Sorry I don't have more information than that.
Re: undefined reference to `WinMain@16' [message #211414 is a reply to message #211325] Sun, 09 March 2008 11:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dschaefer.rogers.com

MG wrote:
> Hi,
> I tried CDT instead VS, because i use Eclipse for java programming.
>
> But if I test compile windows program, it appear error "undefined
> reference to `WinMain@16'". Compiling console app is ok. I searched all
> this forum and all links from Google, but nothing help me.
>
> Here is simple example:
>
> #include "windows.h"
>
> int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR
> lpCmdLine, int nShowCmd)
> {
> MessageBox(NULL, TEXT("Ahoj svete!"), TEXT("Muj pokus"), MB_OK);
> return 0;
> }
>
> Console list:
> **** Internal Builder is used for build ****
> g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\AhojSvete.o
> .\src\AhojSvete.cpp
> .\src\AhojSvete.cpp:7:2: warning: no newline at end of file
> g++ -oAhojSvete.exe src\AhojSvete.o
> /mingw/lib/libmingw32.a(main.o):main.c:(.text+0x104): undefined
> reference to `WinMain@16'
> collect2: ld returned 1 exit status
> Build error occurred, build is stopped
> Time consumed: 2172 ms.
> Running on Eclipse 3.3.1.1, CDT 4.0.3, MinGW-5.1.3, MSYS-1.0.10
>
> Thanks for your help.
>

Believe it or not it's because you have declared the lpCmdLine to be
LPWSTR (wchar_t *) instead of LPSTR (char *). Since the signature
doesn't match, gcc doesn't do it's magic to ensure WinMain gets
generated correctly with the C++ compiler (i.e. without the name mangling).

If you want to use UNICODE you need to use wWinMain.

Doug.
Re: undefined reference to `WinMain@16' [message #211428 is a reply to message #211414] Sun, 09 March 2008 15:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: malekm.centrum.cz

You have absolute right. If I change the type to "LPSTR" and delete
-mwindows from linker its work. And I dint have the second problem with
"unrecognised emulation mode: windows".

Many thanks for your advice.
Re: undefined reference to `WinMain@16' [message #211452 is a reply to message #211428] Sun, 09 March 2008 21:14 Go to previous message
Eclipse UserFriend
Originally posted by: dschaefer.rogers.com

MG wrote:
> You have absolute right. If I change the type to "LPSTR" and delete
> -mwindows from linker its work. And I dint have the second problem with
> "unrecognised emulation mode: windows".
>
> Many thanks for your advice.
>

The mingw is always -mwindows. You can't turn it off. I actually think
it's a cygwin specific option that doesn't exist in the mingw compiler.

Glad things worked for you.

Cheers,
Doug.
Previous Topic:Restarting debug sessions fails
Next Topic:Error launching external scanner info generator at random intervals
Goto Forum:
  


Current Time: Tue May 06 17:58:40 EDT 2025

Powered by FUDForum. Page generated in 0.03858 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top