OpenGL files in C language cannot be compiled.

Asked 2 years ago, Updated 2 years ago, 366 views

I got a mysterious error.It happens every time with GlutMainLoop.Could you tell me the solution here?

y);
      |  ^~~~~~~~~~~~~~~
opengltest.c:11:2:warning:implicit declaration of function 'glutMainLoop' [-Wimplicit-function-declaration]
   11 | glutMainLoop();
      |  ^~~~~~~~~~~~
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc4gTgeX.o:opengltest.c: (.text+0x1c): undefined reference to `glutInput'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc4gTgeX.o:opengltest.c: (.text+0x28): undefined reference to `glutCreate' Window
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc4gTgeX.o:opengltest.c: (.text+0x34): undefined reference to `glutDisplay'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc4gTgeX.o:opengltest.c: (.text+0x39): undefined reference to `glutLoMain'
collect2.exe:error:ld returned1 exit status

Here's the source code.

#include<GL/gl.h>
# include <stdio.h>
# include <GL/glut.h>

void display (void);

int main(intargc, char*argv[]){
    glutInit(&argc,argv);
    glutCreateWindow("hoge");
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

void display() {
    // PASS!
}

c opengl

2022-11-13 07:08

1 Answers

The code for the question is

#include<GL/glut.h>

However, this is considered to be GLUT-The OpenGL Utility Toolkit.Link to

We direct you to use FreeGLUT found on SourceForge: http://freeglut.sourceforge.net/.The original GLUT has been supported for 20 years.

It is only described in a rather careless way.On closer inspection, the final version of GLUT, 3.7 was released on May 7, 1998, but the supported operating systems are Windows 95 and NT.It has not been maintained since then.

This is not a highly recommended library at this time.Of course, using a compatible library is one way, as the link is provided, but in that case, the questioner himself must first recognize that he will use a compatible library of GLUT, which was no longer supported 24 years ago.Even if you make a mistake, you should not think that OpenGL is a C language file.

By the way, may it have been an error in #include<GL/glut.h>? Do you understand that if you have done something about it, no third party will know how to deal with it unless it is explained?

Separately, the error message indicates that MinGW32 is being used on Windows, but the standard compiler for Windows is Visual C++.
If you are using other compilers, of course you should be aware of the differences from standard compilers.If so, the questionnaire should specify which compiler you are using.


2022-11-13 07:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.