LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2004, 08:22 PM   #1
xuniL1
LQ Newbie
 
Registered: Sep 2004
Posts: 2

Rep: Reputation: 0
Angry [c++ / glut] program will not compile (missing references)


Hello,
I have been spending hours trying to figure out why my code will not compile. I hope somebody here can shed some light on this problem. I should say I am new to OpenGL programming and fairly new to linux as well. Anyway...

The code is here:
Code:
// OpenGL demo 2

#ifdef WIN32
  #include <windows.h>
  #define M_PI 3.14159
#endif

#ifdef __APPLE_CC__
  #include <OpenGL/gl.h>
  #include <OpenGL/glu.h>
  #include <GLUT/glut.h>
#else
  #include <GL/glut.h>
  #include <GL/glu.h>
  #include <GL/gl.h>
#endif

#include <math.h>
#include <iostream>
using namespace std;

float r = 0.5;
float theta = 0;
float c = 0;

void display() {

  
	glClear( GL_COLOR_BUFFER_BIT );

	glColor3f( c, 0.5, 0.5 );
	glBegin( GL_POLYGON );

	glVertex2f( r*sin(theta),          r*cos(theta) );
	glVertex2f( r*sin(theta+M_PI*0.5), r*cos(theta+M_PI*0.5) );
	glVertex2f( r*sin(theta+M_PI),     r*cos(theta+M_PI)     );
	glVertex2f( r*sin(theta+M_PI*1.5), r*cos(theta+M_PI*1.5) );

	glEnd();

	glFlush();

}


void idle() {			// *****
  static float t = 0;

  r = sin(t);
  theta = t;
  t += 0.05;

  c = t - floor(t);

  cout << '\r' << t << "   ";
  cout.flush();


#ifndef WIN32
  usleep(30000);
#endif

  glutPostRedisplay();
}

int main( int argc, char **argv ) {
  glutInit( &argc, argv );
  glutInitDisplayMode( GLUT_RGB );
  glutInitWindowPosition( 100, 100 );
  glutInitWindowSize( 600, 600 );
  glutCreateWindow( "demo" );
  glutDisplayFunc( display );
  glutIdleFunc( idle );		// *****
  glutMainLoop();
  return 0;
// OpenGL demo 2
I am running the command: g++ idle.c -o idle

the output i get is:
[user2@192 idlefunction]$ g++ idle.c -o idle
/home/user2/tmp/cck5DI6n.o(.text+0xf): In function `display()':
: undefined reference to `glClear'
/home/user2/tmp/cck5DI6n.o(.text+0x2c): In function `display()':
: undefined reference to `glColor3f'
/home/user2/tmp/cck5DI6n.o(.text+0x39): In function `display()':
: undefined reference to `glBegin'
/home/user2/tmp/cck5DI6n.o(.text+0x7d): In function `display()':
: undefined reference to `glVertex2f'
/home/user2/tmp/cck5DI6n.o(.text+0xeb): In function `display()':
: undefined reference to `glVertex2f'
/home/user2/tmp/cck5DI6n.o(.text+0x159): In function `display()':
: undefined reference to `glVertex2f'
/home/user2/tmp/cck5DI6n.o(.text+0x1c7): In function `display()':
: undefined reference to `glVertex2f'
/home/user2/tmp/cck5DI6n.o(.text+0x1cf): In function `display()':
: undefined reference to `glEnd'
/home/user2/tmp/cck5DI6n.o(.text+0x1d4): In function `display()':
: undefined reference to `glFlush'
/home/user2/tmp/cck5DI6n.o(.text+0x28a): In function `idle()':
: undefined reference to `glutPostRedisplay'
/home/user2/tmp/cck5DI6n.o(.text+0x2ab): In function `main':
: undefined reference to `glutInit'
/home/user2/tmp/cck5DI6n.o(.text+0x2b8): In function `main':
: undefined reference to `glutInitDisplayMode'
/home/user2/tmp/cck5DI6n.o(.text+0x2c7): In function `main':
: undefined reference to `glutInitWindowPosition'
/home/user2/tmp/cck5DI6n.o(.text+0x2dc): In function `main':
: undefined reference to `glutInitWindowSize'
/home/user2/tmp/cck5DI6n.o(.text+0x2ec): In function `main':
: undefined reference to `glutCreateWindow'
/home/user2/tmp/cck5DI6n.o(.text+0x2fc): In function `main':
: undefined reference to `glutDisplayFunc'
/home/user2/tmp/cck5DI6n.o(.text+0x30c): In function `main':
: undefined reference to `glutIdleFunc'
/home/user2/tmp/cck5DI6n.o(.text+0x314): In function `main':
: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

I read on another thread where somebody suggested to edit the /etc/ld.so.conf file, so here is what my ld.so.conf file contains:

/usr/X11R6/lib
/usr/lib/qt3/lib
/usr/X11R6/include/GL
/usr/include/c++/3.3.2
/usr/lib
/usr/lib/GL

I am running mandrake linux 10.0 and have installed glut-3.7.tar.gz

Any help is much appreciated.
Thanks in advance!
 
Old 09-19-2004, 08:43 PM   #2
xuniL1
LQ Newbie
 
Registered: Sep 2004
Posts: 2

Original Poster
Rep: Reputation: 0
After playing around a little more i finally got it to run! It only took 2 days -> yes!
I used the command:

g++ -o idle idle.c -L/usr/X11R6/lib -lglut -lGL -lGLU -lXi -lX11 -lXext -lXmu -lm

Now, i do not know why this works... if anyone cares to explain i would love to understand why... next step...figuring out how to make this work using a makefile.............................
 
Old 09-21-2004, 05:17 AM   #3
hack_in_box
LQ Newbie
 
Registered: Sep 2004
Location: India
Distribution: Fedora core1, PCQ Linux2004, SuSE8
Posts: 13

Rep: Reputation: 0
The reason is that by default gcc doesnt know the header files or the functions used. To actually use libraries outside the standard c/c++ realm u need to tell the path to the library. Also in case of OpenGL the library takes help of native Xlib to do the rendering. Hence u need to compile it against the Xlib. So the Xlib flags<code>
-lXi -lX11 -lXext -lXmu</code> and the GLU flags for GLU library.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple program using openGL in GLUT poeta_boy Programming 14 07-11-2004 05:40 PM
file GL/glut.h missing corbis_demon Linux - Newbie 2 06-30-2004 04:59 PM
Glut Compile Error -- Please Help BenRichards Linux - Software 1 05-28-2004 05:26 PM
GL/glut.j missing qwijibow Linux - Newbie 2 07-23-2003 10:52 PM
glut compile probs isajera Programming 0 06-28-2001 06:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration