LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++
Asked Answered
B

8

44

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.

Blear answered 12/6, 2013 at 16:12 Comment(6)
just because of this website, I had to change them |:' they are: #include <stdlib.h> and: #include <GL/glfw.h>Blear
If you mark your code as code, by indenting every line four spaces with an empty line above and below (or by clicking the {} button with the code highlighted), the pound signs will be treated properly.Testy
Is this cpp file part of your MS project? If you right click on it, does it say "Build Action | Compile"?Dedal
Yes, It successfully compiles it, but when I try to debug it, it throws fatal error.Blear
It compiles, but does not link, therefore you cannot run your application to begin debugging it.Sweetscented
Microsoft's C/C++ compiler behaves differently when compiling for the first time. See https://mcmap.net/q/239139/-winmain-and-main-in-c-extendedBedlamite
L
29

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.

Laomedon answered 12/6, 2013 at 16:36 Comment(7)
Right-click on the Project (not on the topmost Solution entry), then Configuration Properties ...Laomedon
Now I got to the point where SubSystem should say "windows"... It says nothing about it. empty slot.Blear
Topmost entry in that properties page. Not sure if it is Windows there (may as well be Console), but if it is Windows, then your main function needs to be renamed.Laomedon
I have VS2005, it may be different on yours. Or it may even be another reason for the error.Laomedon
SubSystem is just a blank line. should I rename it to WinMain() anyways?Blear
You can try (or there is a dropdown with values). Otherwise rebuild the project and make sure you choose a Win32 Console (main()) or Win32->Win32 App (WinMain())Laomedon
This is criminally inaccurate. While it appears to work sometimes, it will fail in subtle ways. The user-provided entry point is not the process entry, if you are using the CRT. You need to set the CRT's entry point instead, since it performs necessary initialization (e.g. running static initializers). When using Microsoft's compiler (and CRT), the entry point should be WinMainCRTStartup (or wWinMainCRTStartup).Personification
S
12

In my case, the program was running fine, but after one day, I just ran into this problem without doing anything...

The solution was to manually add 'Main' as the Entry Point (before editing, the area was empty):

enter image description here

Strangulate answered 7/2, 2017 at 3:56 Comment(0)
S
8

It cant find the entry point for your program, in this case main(). Your linker settings are likely incorrect.

See this post here

Sweetscented answered 12/6, 2013 at 16:44 Comment(0)
D
8

change it to Console (/SUBSYSTEM:CONSOLE) it will work

Decipher answered 31/1, 2015 at 21:30 Comment(2)
cl : Command line warning D9002 : ignoring unknown option '/SUBSYSTEM:CONSOLE'Assiniboine
Note: the flag should be passed to the linker, not the compiler. cl is the compiler. So if you're using cl to build the exe, use the /link flag. See also social.msdn.microsoft.com/Forums/en-US/…Carmeliacarmelina
A
7

You can get this error if you define a project as an .exe but intent to create a .lib or a .dll

Abbacy answered 25/9, 2017 at 11:19 Comment(0)
R
1

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.

Rabat answered 29/10, 2015 at 1:15 Comment(0)
L
0

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.

Ljoka answered 30/12, 2016 at 17:51 Comment(1)
By the way, some days ago in a lecture I heard that it's not advised making a function other than 'main' the entry function.Ljoka
T
0

Main was missing in the entry point configuration. enter image description here

Tsar answered 31/7, 2018 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.