I am compiling this OpenGL program in Visual Studio. I have set it up properly, after reading numerous articles. I have added the correct libraries to linker’s additional dependencies. However I am getting this error:
error LNK2019: unresolved external symbol WinMain@16 referenced in function __tmainCRTStartup
The code I am compiling is:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
/* viewing transformation */
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); /* modeling transformation */
glutWireCube (1.0);
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
There are two kind of executables in Windows:
Only difference is that Console executables automatically opens console window, and C/C++ CRT runtime associates standart stdout/stdin/stderr handles to go to this window. Otherwise there are no differences between these two executable types – both can create new Windows, draw things, use OpenGL, etc…
In visual Studio, if you create Console application – then it expects your entry point to be called “main”. But for GUI application it expects entry point function to be called “WinMain”. So you have two options if you don’t want to see Console window when your application starts:
Using second options means, that you can use GLUT, have your entry point called “main” and have no Console window opened at startup.