I want to compile a GLUT program
#include <GL/glut.h>
int main(int argc, char **argv) {
// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Lighthouse3D- GLUT Tutorial");
return 1;
}
Compile and link command:
gcc -o main.exe main.c -lglut32
Result:
main.o:main.c:(.text.startup+0x1c): undefined reference to `glutInit'
main.o:main.c:(.text.startup+0x28): undefined reference to `glutInitDisplayMode'
main.o:main.c:(.text.startup+0x3c): undefined reference to `glutInitWindowPosition'
main.o:main.c:(.text.startup+0x50): undefined reference to `glutInitWindowSize'
main.o:main.c:(.text.startup+0x5c): undefined reference to `glutCreateWindow'
collect2: ld returned 1 exit status
The actual lib file of glut (3.7.6, called glut32.lib) is in the lib folder of mingw and the include file in include/GL.
What to do now?
Try it with
libglut.aandlibglut32.ainstead ofglut32.lib. To compile glut programs with minGW.Do GLUT for Win32 is a Windows port of the original GLUT library. It’s no longer maintained or supported. The MinGW “w32api” package already comes with two GLUT import libraries, “libglut.a” and “libglut32.a”, but doesn’t come with a glut header file.
If you’ve ever downloaded a GLUT header from the internet, and attempted to link an application against either of these import libraries, you likely would have seen it fail with various undefined references.
Setting Up GLUT for Win32 With MinGW Look for
Setting Up GLUT for Win32 With MinGWIf you want to have your own “build” of libglut32.a and glu32.dll.
Add the following lines to include/GL/glut.h starting at line 12:
Comment out line 21 in lib/glut/win32_winproc.c so that it looks:
makefile line 5 replace:
-enable-auto-import with –enable-auto-import
run make
Have tried it with the example.c file from the guidance in the link
Setting Up GLUT for Win32 With MinGW.With the prebuild libs and the self compiled libs. Works both.
below is the result.
Example GLUT Application
example.c from the link above
Setting Up GLUT for Win32 With MinGW.