Hey guys,

I'm stuck on some undefined references to glut and OpenGL, even when I linked my projects with the correct libraries. Well apparently they aren't correct...

I'm trying to compile this:

/* Copyright (c) Mark J. Kilgard, 1994. */

/* This program is freely distributable without licensing fees 
   and is provided without guarantee or warrantee expressed or 
   implied. This program is -not- in the public domain. */

#include <GL/glut.h>

GLfloat light_diffuse[] =
{1.0, 0.0, 0.0, 1.0};
GLfloat light_position[] =
{1.0, 1.0, 1.0, 0.0};
GLUquadricObj *qobj;

void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glCallList(1);        /* render sphere display list */
  glutSwapBuffers();
}

void
gfxinit(void)
{
  qobj = gluNewQuadric();
  gluQuadricDrawStyle(qobj, GLU_FILL);
  glNewList(1, GL_COMPILE);  /* create sphere display list */
  gluSphere(qobj, /* radius */ 1.0, /* slices */ 20,
  /* stacks */ 20);
  glEndList();
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_DEPTH_TEST);
  glMatrixMode(GL_PROJECTION);
  gluPerspective( /* field of view in degree */ 40.0,
  /* aspect ratio */ 1.0,
    /* Z near */ 1.0, /* Z far */ 10.0);
  glMatrixMode(GL_MODELVIEW);
  gluLookAt(0.0, 0.0, 5.0,  /* eye is at (0,0,5) */
    0.0, 0.0, 0.0,      /* center is at (0,0,0) */
    0.0, 1.0, 0.);      /* up is in positive Y direction */
  glTranslatef(0.0, 0.0, -1.0);
}

int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutCreateWindow("sphere");
  glutDisplayFunc(display);
  gfxinit();
  glutCreateWindow("a second window");
  glutDisplayFunc(display);
  gfxinit();
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}

And added these options to the linker (according to code::blocks):
-lopengl32
-lglu32
-lglut32

And getting these errors:

.objs\drivertest.o:drivertest.cpp:(.text+0x1c)||undefined reference to `__glutInitWithExit'|
.objs\drivertest.o:drivertest.cpp:(.text+0x37)||undefined reference to `__glutCreateWindowWithExit'|
.objs\drivertest.o:drivertest.cpp:(.text+0x53)||undefined reference to `__glutCreateMenuWithExit'|
.objs\drivertest.o:drivertest.cpp:(.text+0x68)||undefined reference to `_imp__glClear'|
.objs\drivertest.o:drivertest.cpp:(.text+0x76)||undefined reference to `_imp__glCallList'|
.objs\drivertest.o:drivertest.cpp:(.text+0x7d)||undefined reference to `glutSwapBuffers'|
.objs\drivertest.o:drivertest.cpp:(.text+0x8b)||undefined reference to `_imp__gluNewQuadric'|
.objs\drivertest.o:drivertest.cpp:(.text+0xa7)||undefined reference to `_imp__gluQuadricDrawStyle'|

etc.

Any clues?

Thanks in advance,
Nick

do a Google search using phrase, OpenGL tutorial. Then select tutorial at NeHe.com. They instruct you to use a Win32 project, not a console project, and they included these headers in their initial project:

#include <windows.h> // Header File For Windows
#include <gl\gl.h>// Header File For The OpenGL32 Library
#include <gl\glu.h>// Header File For The GLu32 Library
#include <gl\glaux.h>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.