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:
- OpenGL learning — problems encountered in compiling OpenGL program for the first time
- A solution to the problem of “straight ‘\ 357’ in program” when compiling GCC
- Summary of problems encountered in compiling opengl code
- OpenGL program running prompt glut32.dll missing problem
- Cannot run program “make” when compiling APM firmware with eclipse under Windows: launching failed problem
- Small problems encountered in compiling OpenGL under VS2010
- A strange upgrade data package error problem
- After the vs2013 + OpenGL environment is set up, there is an error in running the first program
- Vs compiling OpenGL project, the solution of unable to open the source file “GL / glaux. H” appears
- Configuring OpenGL in Chinese version of VS2010 and problem solving
- Python program uses OS. System () method to call exe program, resulting in no response of main program process
- To solve the problem of flashback of calling class function of glutsolidcube() in Win32 program
- 0028opengl program running prompt glut32.dll missing one of the solutions
- Solve the problem of “A TimThumb error has occured” in the WordPress program
- Visual studio 2017, OpenGL program running prompt glut32.dll missing solution
- [OpenGL] cannot start this program because the computer is missing glut32.dll. Try to re install the program to fix this problem. …
- C language — to solve the problem of program flashback when programming (in VS)
- 076_ OpenGL graphics program development practice
- There was a problem sending the command to the program in Excel 2010
- Solution to the problem that OpenGL can’t find glew32.dll in vs2019