Jump to content

  • Log In with Google      Sign In   
  • Create Account

Having problems getting opengl working with mingw

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1   Members   -  Reputation: 122


Posted 28 September 2008 - 01:07 PM

After spending the last four hours trying to get this working, I'm resorting to asking for help. I've installed MinGW on my XP64 machine, along with GLUT. I've put glut.h in C:\MinGW\include\GL, libglut32.a in C:\MinGW\lib and glut32.dll in C:\WINDOWS\system32. When I try to run a sample program, I get the following:
g++ helloGL.cpp -lopengl32 -lglu32 -lglut32
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x1c): undefined reference to `__glutInitWithExit'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x37): undefined reference to `__glutCreateWindowWithExit'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x53): undefined reference to `__glutCreateMenuWithExit'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x7e): undefined reference to `_imp__glViewport'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x8c): undefined reference to `_imp__glMatrixMode'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x93): undefined reference to `_imp__glLoadIdentity'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0xc9): undefined reference to `_imp__glOrtho'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0xd7): undefined reference to `_imp__glMatrixMode'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0xee): undefined reference to `_imp__glClear'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0xf5): undefined reference to `_imp__glLoadIdentity'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0xfc): undefined reference to `glutSwapBuffers'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x12c): undefined reference to `_imp__glClearColor'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x13a): undefined reference to `_imp__glEnable'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x186): undefined reference to `glutInitDisplayMode'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x19a): undefined reference to `glutInitWindowSize'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x1b2): undefined reference to `glutDisplayFunc'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x1be): undefined reference to `glutReshapeFunc'
C:\.../ccY1lEyc.o:helloGL.cpp:(.text+0x1c8): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
Here's my code, which I'm assuming works since I got it from a tutorial.
#include <stdlib.h>
#include <GL/glut.h>

void keyboard(unsigned char key, int x, int y);
void display(void);

int main(int argc, char** argv)
  glutInit(&argc, argv);
  glutCreateWindow("GLUT Test");

  return EXIT_SUCCESS;

void keyboard(unsigned char key, int x, int y)
  switch (key)
    case '\x1B':

void display()

  glColor3f(1.0f, 0.0f, 0.0f);

    glVertex2f(-0.5f, -0.5f);
    glVertex2f( 0.5f, -0.5f);
    glVertex2f( 0.5f,  0.5f);
    glVertex2f(-0.5f,  0.5f);


Thanks in advanced.

#2   Members   -  Reputation: 206


Posted 29 September 2008 - 12:25 AM

I'm going to go out on a limb here and say it's got something to do with you not telling it which directories to look in for the libraries (I've had quite a few issues with it myself, which is why I just get CodeBlocks to do everything for me now). Try using this:
g++ -LC:/MinGW/lib helloGL.cpp -lopengl32 -lglu32 -lglut32

#3   Members   -  Reputation: 122


Posted 30 September 2008 - 07:09 AM

Thanks for the response. Unfortunately that didn't work.

#4   Members   -  Reputation: 206


Posted 30 September 2008 - 09:49 PM

Apparently they've changed the compiler since way back when... Seems you have to include the libraries in the compiling line in addition to any source files these days (at least that's what Code Blocks is doing). The end result being:
g++ helloGL.cpp C:/MinGW/libopengl32.a C:/MinGW/libglu32.a C:/MinGW/libglut32.a -o helloGL.exe

I added the output target too, that way you don't end up with 'a.exe', which can be a little annoying if you plan on compiling multiple things in the same directory. You might need to add libgdi32.a too (depending on how glut works). That should fix your problem though.

#5   Members   -  Reputation: 122


Posted 01 October 2008 - 02:35 AM

Thanks again.

I ended up just installing Code Blocks and following the tutorial, and that seems to have gotten it working.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.