Here is my directory:
graphics/
glut.h
glut32.dll
glut32.lib
simple.c
Here is my program:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "glut.h"
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5,-0.5);
glVertex2f(-0.5,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,-0.5);
glEnd();
glFlush();
return;
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("simple");
glutDisplayFunc(display);
glutMainLoop();
}
When I try to compile using the following command
gcc simple.c -o MyProg glut32.lib -lopengl32 -lglu32
I get the following errors:
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x28): undefined reference to `__imp___glutInitWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x52): undefined reference to `__imp___glutCreateWindowWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x7b): undefined reference to `__imp___glutCreateMenuWithExit'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x162): undefined reference to `__imp_glutDisplayFunc'
C:\Users\Jake\AppData\Local\Temp\ccehzclV.o:simple.c:(.text+0x16b): undefined reference to `__imp_glutMainLoop'
collect2.exe: error: ld returned 1 exit status
I've tried every answer I can find, I've reinstalled MinGW, and I've reinstalled tdm-gcc. Nothing has worked, I'm hoping someone can shine some light on this.
EDIT: I've also added glut32.dll to system32 with no luck.
gcc simple.c -o MyProg -lglut32 -lglu32 -lopengl32 -lmingw32
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglut32
gcc simple.c -o MyProg -lc:\path\to\the\file\glut32 -lglu32 -lopengl32 -lmingw32
. One more correction: once you compile it cleanly, you may need to move (or copy) theglut32.dll
file(s) into the executable path (\Debug
or\Release
).glut32
in the-lc:\path\to\the\file\glut32
part isglut32.lib
(do not type the.lib
extension in the compilation line). However, the file you need to copy into the executable files folder path is theglut32.dll
.gcc simple.c -o MyProg -l C:\Users\Jake\Desktop\graphics\glut32 -lglu32 -lopengl32 -lmingw32
returns the error:C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lC:\Users\Jake\Desktop\graphics\glut32