C++ 链接:致命错误 LNK1561:必须在 VC++ 中定义入口点错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17070367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
提问by SortOf
I installed MS VS VC++ for the first time in order to start programming OpenGL with GLFW library. I follower instructions on how to install it over at http://shawndeprey.blogspot.com/2012/02/setting-up-glfw-in-visual-studio-2010.htmlThen I wrote this simple program, just to test it, which did work on Eclipse:
我第一次安装了 MS VS VC++,以便开始使用 GLFW 库对 OpenGL 进行编程。我在http://shawndeprey.blogspot.com/2012/02/setting-up-glfw-in-visual-studio-2010.html上遵循有关如何安装它的说明 然后我编写了这个简单的程序,只是为了测试它,它确实在 Eclipse 上工作:
#include <stdlib.h>
#include <GL/glfw.h>
using namespace std;
int main()
{
int running = GL_TRUE;
if (!glfwInit()) {
exit(EXIT_FAILURE);
}
if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
glfwTerminate();
exit(EXIT_FAILURE);
}
while (running) {
// glClear( GL_COLOR_BUFFER_BIT );
glfwSwapBuffers();
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
}
glfwTerminate();
exit(EXIT_SUCCESS);
return 0;
}
But then I got this awful error:
但后来我得到了这个可怕的错误:
------ Build started: Project: first1, Configuration: Debug Win32 ------
LINK : fatal error LNK1561: entry point must be defined
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I know, I've looked around on the internet and the only solution I found was "It requires main()
function in order to work". I obviously have it, right there, but it still throws me the same fatal error :(
我知道,我在互联网上环顾四周,我发现的唯一解决方案是“它需要main()
功能才能工作”。我显然有它,就在那里,但它仍然给我抛出同样的致命错误:(
Would be great to get response on how to fix it. There might me a flaw in the installation process or something.
能得到关于如何修复它的回应会很棒。安装过程中可能存在缺陷或其他什么。
回答by collaborator
Is this a console program project or a Windows project? I'm asking because for a Win32 and similar project, the entry point is WinMain()
.
这是控制台程序项目还是 Windows 项目?我问是因为对于 Win32 和类似项目,入口点是WinMain()
.
- Right-click the Project (not the Solution) on the left side.
- Then click Properties -> Configuration Properties -> Linker -> System
- 右键单击左侧的项目(不是解决方案)。
- 然后点击属性 -> 配置属性 -> 链接器 -> 系统
If it says Subsystem Windows
your entry point should be WinMain(), i.e.
如果它说Subsystem Windows
你的入口点应该是 WinMain(),即
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
your code here ...
}
Besides, speaking of the comments. This is a compile (or more precisely a Link) error, not a run-time error. When you start to debug, the compiler needs to make a complete program (not just to compile your module) and that is when the error occurs.
此外,说到评论。这是编译(或更准确地说是链接)错误,而不是运行时错误。当你开始调试时,编译器需要制作一个完整的程序(不仅仅是编译你的模块),这就是错误发生的时候。
It does not even get to the point being loaded and run.
它甚至没有达到被加载和运行的地步。
回答by ash
It cant find the entry point for your program, in this case main()
. Your linker settings are likely incorrect.
在这种情况下,它无法找到您的程序的入口点main()
。您的链接器设置可能不正确。
See this post here
回答by Michelangelo Machado
回答by Matas Lesinskas
change it to Console (/SUBSYSTEM:CONSOLE) it will work
将其更改为 Console (/SUBSYSTEM:CONSOLE) 它将起作用
回答by Michael Haephrati
You can get this error if you define a project as an .exe but intent to create a .lib or a .dll
如果您将项目定义为 .exe 但打算创建 .lib 或 .dll,则可能会出现此错误
回答by sdff
I've had this happen on VS after I changed the file's line endings. Changing them back to Windows CR LF fixed the issue.
在更改文件的行尾后,我在 VS 上发生了这种情况。将它们改回 Windows CR LF 解决了该问题。
回答by Brackets
In Visual Studio:
Properties ->
Advanced ->
Entry Point ->
write just the name of the function you want the program to begin running from, case sensitive, without any brackets and command line arguments.
在 Visual Studio 中:属性->
高级->
入口点->
只写你希望程序开始运行的函数的名称,区分大小写,没有任何括号和命令行参数。