【问题标题】:Compile error with winmain and simple code, "Previous decleration of WinMain"使用 winmain 和简单代码编译错误,“WinMain 的先前声明”
【发布时间】:2021-06-18 12:48:22
【问题描述】:
#include <stdio.h> 
#include <windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    return(0);
}

我是 C 新手。上面的代码在我尝试编译时返回以下错误:

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);

【问题讨论】:

  • 你把上面的代码放在哪里了?它在 main 之上吗?
  • 我没有主文件。我需要一个吗?上面的代码是我项目的全部代码。 @AsafItach
  • 仍然出现同样的错误。
  • windws.h 是一个头文件,可让您为 Windows 编译程序,根据维基百科,它自动包含定义 HINSTANCE 的 windef.h。手动包含 windef.h 并不能解决错误。

标签: c gcc mingw winmain


【解决方案1】:

您应该使函数定义与库的声明相匹配。你有

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

这是必须的

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

缺少APIENTRY

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-29
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 2017-05-10
    相关资源
    最近更新 更多