Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

Tags:

c++

This is my script i have no idea to solve this error Please help me Thank you so much

float angle = 15;
float x, y, z;               // for polygon rotate 

void display()
{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // clear screen and depth buffer
    glLoadIdentity();

    glPushMatrix();

    glColor3f(1.0, 0.0, 0.0);

    glBegin(GL_POLYGON);


    glVertex2f(160.0, 360.0);
    glVertex2f(300.0, 360.0);
    glVertex2f(160.0, 480.0);
    glVertex2f(300.0, 480.0);

    glPushMatrix();

    glColor3f(0.0, 0.0, 0.0);
    glVertex2f(580.0, 200.0);
    glVertex2f(640.0, 200.0);
    glVertex2f(580.0, 480.0);
    glVertex2f(640.0, 480.0);

    glRotatef(angle, -1.0f, 0.0, 0.0);

    angle += 15.0f;






    glEnd();




    glutSwapBuffers(); // dounle buffering

}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_LBUTTONDOWN:
    {



    }break;

    case WM_DESTROY: {


        PostQuitMessage(0);

    }break;


    default:break;
    }
    return 0;
}



int main(int argc, char** argv)
{
    glutInit(&argc, argv); // Initialize GLUT

    glutInitDisplayMode(GLUT_DOUBLE);// Set up some memory buffers for our display


    glutInitWindowSize(640, 400);
    glutInitWindowPosition(100, 20);
    glutCreateWindow("My GLUT GAME");
    glutDisplayFunc(display);
    //glutKeyboardFunc();


    glutMainLoop();
    return 0;
}
like image 959
Choiyan Wong Avatar asked Dec 14 '16 11:12

Choiyan Wong


2 Answers

As workaround you can add WinMain function from which call main:

#ifdef _WIN32
int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    return main(__argc, __argv);
}
#endif
like image 68
Alexander Ushakov Avatar answered Sep 17 '22 16:09

Alexander Ushakov


I had to make the application as executable project with output type .exe Key change was changing Linker -> System -> Sub-system to Console

enter image description here

like image 45
Morse Avatar answered Sep 20 '22 16:09

Morse