链接:致命错误 LNK1561:必须在 VC++ 中定义入口点错误

2021-12-22 00:00:00 visual-studio visual-c++ c++

我第一次安装了 MS VS VC++,以便开始使用 GLFW 库对 OpenGL 进行编程.我在 http://shawndeprey.blogspot.com/2012/02/setting-up-glfw-in-visual-studio-2010.html然后我写了这个简单的程序,只是为了测试它,它确实在 Eclipse 上工作:

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.html Then I wrote this simple program, just to test it, which did work on 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 ==========

我知道,我在互联网上环顾四周,我找到的唯一解决方案是它需要 main() 函数才能工作".我显然有它,就在那里,但它仍然给我抛出同样的致命错误:(

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 :(

如果能得到关于如何修复它的回应会很棒.可能是我安装过程中的缺陷什么的.

Would be great to get response on how to fix it. There might me a flaw in the installation process or something.

推荐答案

这是控制台程序项目还是 Windows 项目?我问是因为对于 Win32 和类似项目,入口点是 WinMain().

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().

  1. 右键单击左侧的项目(而不是解决方案).
  2. 然后点击属性 -> 配置属性 -> 链接器 -> 系统

如果它说 Subsystem Windows 你的入口点应该是 WinMain(),即

If it says Subsystem Windows your entry point should be WinMain(), i.e.

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.

相关文章