简体   繁体   English

Win32应用程序LNK2001:无法解析的外部符号_main

[英]Win32 Application LNK2001: unresolved external symbol _main

I have been trying to make a WIN32 Application with a GUI (NOT a simple console application) on VS2012, and I'm stuck with this one error. 我一直试图在VS2012上使用GUI(不是简单的控制台应用程序)制作WIN32应用程序,但我一直陷在这个错误中。 My project is on Release configuration. 我的项目在Release配置上。 My main function looks like this: 我的主要功能如下:

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{

    return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
}

What I've tried: 我尝试过的

1) Creating a new WIN32 Project with these settings: 1)使用以下设置创建一个新的WIN32项目:

  • Application Type -> Windows application 应用程序类型-> Windows应用程序
  • Additional options -> Empty Project (With NO SDL!) 附加选项->空项目(无SDL!)
  • No other options checked 没有检查其他选项

2) Changing between Unicode and Multi-Byte Character Sets 2)在Unicode和多字节字符集之间切换

3) Changing the SubSystem (from Windows (/SUBSYSTEM:WINDOWS) to Not Set) 3)更改子系统(从Windows(/ SUBSYSTEM:WINDOWS)设置为未设置)

4) Adding entry points (main ; _main ; WinMain) 4)添加入口点(main; _main; WinMain)

5) Adding #undef _ATL_MIN_CRT (I'm pretty sure it was disabled anyway, but still did it for extra insurance...) 5)添加#undef _ATL_MIN_CRT(我很确定它还是被禁用了,但仍然这样做是为了额外的保险...)

NONE of these solved my issue. 这些都没有解决我的问题。 I've searched the Internet and haven't found anyone with a similar problem (creating a WIN32 Application) who has solved their issue. 我已经搜索了Internet,却没有找到解决类似问题的任何人(创建WIN32应用程序)。

EDIT : I'm also using Allegro 5 library and I'm building the program with /MT . 编辑 :我也在使用Allegro 5库,并且正在使用/ MT构建程序。

Any recommendations are welcome. 欢迎任何建议。

The problem is that you're using the wrong calling convention for your main function. 问题是您为main功能使用了错误的调用约定。 As the documentation for Name Decoration explains, a symbol with a leading underscore and no other decorations indicates C calling convention . 正如名称修饰的文档所解释的那样,带下划线的符号和没有其他修饰的符号表示C调用约定

The signature for your main function should be: main功能的签名应为:

extern "C" __cdecl void main();

Note that neither the return value nor the argument list are part of the name decoration, since the caller is responsible for cleanup. 请注意,返回值和参数列表都不是名称修饰的一部分,因为调用者负责清理。 This means that any function signature can be used to satisfy the linker. 这意味着任何函数签名都可以用来满足链接器的要求。

After some searching I've found the answer. 经过一番搜索,我找到了答案。

All I needed to do was to define ALLEGRO_NO_MAGIC_MAIN . 我要做的就是定义ALLEGRO_NO_MAGIC_MAIN。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM