| 
| undefined reference to `WinMain@16' [message #211325] | Sat, 08 March 2008 04:01  |  | 
| Eclipse User  |  |  |  |  | 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 #211414 is a reply to message #211325] | Sun, 09 March 2008 11:49   |  | 
| Eclipse User  |  |  |  |  | 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 #211452 is a reply to message #211428] | Sun, 09 March 2008 21:14  |  | 
| Eclipse User  |  |  |  |  | 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.
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.47572 seconds