Sign in to follow this  
Pellanor

OpenGL Having problems getting opengl working with mingw

Recommended Posts

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");
  glutKeyboardFunc(&keyboard);
  glutDisplayFunc(&display);
  glutMainLoop();

  return EXIT_SUCCESS;
}


void keyboard(unsigned char key, int x, int y)
{
  switch (key)
  {
    case '\x1B':
      exit(EXIT_SUCCESS);
      break;
  }
}


void display()
{
  glClear(GL_COLOR_BUFFER_BIT);

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

  glBegin(GL_POLYGON);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f( 0.5f, -0.5f);
    glVertex2f( 0.5f,  0.5f);
    glVertex2f(-0.5f,  0.5f);
  glEnd();

  glFlush();
}

Thanks in advanced.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this