A strange problem in compiling OpenGL program

I encountered a strange problem compiling an OpenGL program today.
A short code to draw a triangle. The project file contains a CPP file. The project was run correctly before, and is now run correctly when opened. My OpenGL is configured according to this article:
Click the open link. There shouldn’t be any problems.
But when I create a new project and copy the original code, it runs wrong. And I remember building that project before with nothing in it. Why are two engineering pieces of code exactly the same but behave differently?Very depressed ah!
Here is the code:
#include < GL/glut.h> Void init () {glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); // render mode} void triangle() {glBegin(GL_TRIANGLES); GlColor3f (1.0, 0.0, 0.0); GlVertex2f (5.0, 5.0); GlColor3f (0.0, 1.0, 0.0); GlVertex2f (25.0, 5.0); GlColor3f (0.0, 0.0, 1.0); GlVertex2f (5.0, 25.0); glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT); triangle(); glFlush(); Void reshape(int w,int h) {glViewport(0,0,(GLsizei)w,(GLsizei)h); void reshape(int w,int h) {glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w < = h) gluOrtho2D(0.0,30.0,0.0,30.0 * (glFloat)h/(glFloat)w); Else gluOrtho2D(0.0,30.0 * (glFloat)w/(glFloat)h,0.0,30.0); glMatrixMode(GL_MODELVIEW); } int main(int argc,char** argv) { glutInit(& argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); GlutInitWindowSize (500500); GlutInitWindowPosition (100100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } Open the original project and it ran successfully:


But when I create a new project and copy the code exactly as it is, I get an error. Error message:
1> — — — — — – has started to generate: project: Test, configuration: Debug Win32 — — — — — –
1 & gt; Compiling…
1> Test.cpp
1> Linking…
1> LINK: did not find E:\ Learning \ Program Exercise \OpenGL\Test\Debug\Test.exe or last incremental LINK did not generate it; Performing full link
1> Test.obj: error LNK2019: Unable to resolve external symbol __imp____glutInitWithExit@12, which is referenced in function _glutInit_ATEXIT_HACK@8
1>; Test.obj: error LNK2019: Unable to resolve external symbol __imp____glutCreateWindowWithExit@8, which is referenced in function _glutCreateWindow_ATEXIT_HACK@4
1>; E:\ Learning \ Program Practice \OpenGL\Test\Debug\Test.exe: fatal error LNK1120: 2 external commands
1>; Build log is saved in “file:// E :\ Learning \ Program Practice \OpenGL\Test\Test\Debug\BuildLog.htm”
1>; Test – 3 error, zero warning
= = = = = = = = = = : zero success, failure, the latest zero, skip the 0 = = = = = = = = = =

After a long search on the Internet, I finally found a solution: #include lt; GL/glut.h> Before adding the following code:
#ifndef GLUT_DISABLE_ATEXIT_HACK #define GLUT_DISABLE_ATEXIT_HACK #endif But why add this?

It’s still not clear. I hope you know who can help me solve my doubts.


Read More: