使用 winmain 和简单代码编译错误,"Previous decleration of WinMain"
Compile error with winmain and simple code, "Previous decleration of WinMain"
#include <stdio.h>
#include <windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return(0);
}
我是C新手,以上代码returns编译时出现如下错误:
main.c:3:5: error: conflicting types for 'WinMain'
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
^~~~~~~
In file included from c:\mingw\include\windows.h:44:0,
from main.c:2:
c:\mingw\include\winbase.h:1263:14: note: previous declaration of 'WinMain' was here
int APIENTRY WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
您应该使函数定义与库的声明相匹配。你有
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
这需要
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
缺少APIENTRY
。
#include <stdio.h>
#include <windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return(0);
}
我是C新手,以上代码returns编译时出现如下错误:
main.c:3:5: error: conflicting types for 'WinMain'
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
^~~~~~~
In file included from c:\mingw\include\windows.h:44:0,
from main.c:2:
c:\mingw\include\winbase.h:1263:14: note: previous declaration of 'WinMain' was here
int APIENTRY WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
您应该使函数定义与库的声明相匹配。你有
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
这需要
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
缺少APIENTRY
。