Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

c++ - LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++

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 ==========

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.

question from:https://stackoverflow.com/questions/17070367/link-fatal-error-lnk1561-entry-point-must-be-defined-error-in-vc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. Right-click the Project (not the Solution) on the left side.
  2. Then click Properties -> Configuration Properties -> Linker -> System

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...