-1

I'm having a problem getting openGL to work on Windows 7 using MinGW at the moment. I'm following the steps found here: https://www.opengl.org/wiki/MinGW

I have installed MinGW and all of it's basic installation files. I have added the elements required to my PATH variable. I have downloaded and placed the GLUT files in the correct directories as described in the link above. Even so, with the below code I get the subsequent errors.

#include <GL/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 ();
}

The command used to compile this program is: gcc firstProg.c -o firstProg.exe glut32.lib -lopengl32 -lglu32

The error is as follows (taken from the cmd):

C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x1c): undefined
 reference to `__glutInitWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x37): undefined
 reference to `__glutCreateWindowWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x52): undefined
 reference to `__glutCreateMenuWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x66): undefined
 reference to `_imp__glClear'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x74): undefined
 reference to `_imp__glBegin'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x8c): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xa4): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xbc): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xd4): undefined
 reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xdb): undefined
 reference to `_imp__glEnd'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xe2): undefined
 reference to `_imp__glFlush'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x11f): undefine
d reference to `glutDisplayFunc'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x124): undefine
d reference to `glutMainLoop'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\D
ylan\AppData\Local\Temp\cciCuMP6.o: bad reloc address 0x20 in section `.eh_frame
'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
 failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

Anyone here have any idea how to solve these errors? I've tried uninstalling and reinstalling MinGW as well as placing the GLUT files within the required directories again but to no avail.

genpfault
  • 51,148
  • 11
  • 85
  • 139
JengaBlock
  • 53
  • 2
  • 9

1 Answers1

2

Step 1: Make sure you have a properly built GLUT library that matches your compiler toolchain.

Step 2: Actually add GLUT to the list of libraries to link to.

GLUT is a 3rd party library, that's not part of OpenGL (in any way).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Hi datenwolf. The command I used was 'gcc firstProg.c -o firstProg.exe glut32.lib -lopengl32 -lglu32'. This is adding glut to those libraries that I wish to link to, correct? I still have not managed to get this working. Is there a generally recommended way to get GLUT working with openGL and MinGW on a Windows machine? – JengaBlock Feb 28 '15 at 22:04
  • 1
    No it's not. Hint, to specify it as a library to link you use `-lglut32` and add the path where the GLUT library resides to the linker search path using the `-L` option. – datenwolf Feb 28 '15 at 22:38