LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 06-28-2011, 06:36 AM   #1
Hvl
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Rep: Reputation: 0
Compiling errors when compiling OpenGL with GLUT


Hello

I have just started to look at OpenGL, and I got the book "OpenGL Superbible 5th edition" by Richard. S. Wright, jr and others.

The code in the book makes use of various libs', for example GLUT, GLEW and a GLTools (Which is made by the books authors I think).

The problem is that when I compile the code from the first example application I get this error:
Quote:
[hakon@hakon-laptop opengl-superbible]$g++ triangle.cpp -o triangle
/tmp/cctwzBOq.o: In function `ChangeSize(int, int)':
triangle.cpp:(.text+0x23): undefined reference to `glViewport'
/tmp/cctwzBOq.o: In function `SetupRC()':
triangle.cpp:(.text+0x48): undefined reference to `glClearColor'
triangle.cpp:(.text+0x52): undefined reference to `GLShaderManager::InitializeStockShaders()'
triangle.cpp:(.text+0xb3): undefined reference to `GLBatch::Begin(unsigned int, unsigned int, unsigned int)'
triangle.cpp:(.text+0xce): undefined reference to `GLBatch::End()'
/tmp/cctwzBOq.o: In function `RenderScene()':
triangle.cpp:(.text+0xe2): undefined reference to `glClear'
triangle.cpp:(.text+0x11d): undefined reference to `GLShaderManager::UseStockShader(GLT_STOCK_SHADER, ...)'
triangle.cpp:(.text+0x127): undefined reference to `GLBatch::Draw()'
triangle.cpp:(.text+0x12c): undefined reference to `glutSwapBuffers'
/tmp/cctwzBOq.o: In function `main':
triangle.cpp:(.text+0x14c): undefined reference to `gltSetWorkingDirectory(char const*)'
triangle.cpp:(.text+0x15f): undefined reference to `glutInit'
triangle.cpp:(.text+0x169): undefined reference to `glutInitDisplayMode'
triangle.cpp:(.text+0x178): undefined reference to `glutInitWindowSize'
triangle.cpp:(.text+0x182): undefined reference to `glutCreateWindow'
triangle.cpp:(.text+0x18c): undefined reference to `glutReshapeFunc'
triangle.cpp:(.text+0x196): undefined reference to `glutDisplayFunc'
triangle.cpp:(.text+0x19b): undefined reference to `glewInit'
triangle.cpp:(.text+0x1ae): undefined reference to `glewGetErrorString'
triangle.cpp:(.text+0x1d6): undefined reference to `glutMainLoop'
/tmp/cctwzBOq.o: In function `__static_initialization_and_destruction_0(int, int)':
triangle.cpp:(.text+0x204): undefined reference to `GLBatch::GLBatch()'
triangle.cpp:(.text+0x209): undefined reference to `GLBatch::~GLBatch()'
triangle.cpp:(.text+0x225): undefined reference to `GLShaderManager::GLShaderManager()'
triangle.cpp:(.text+0x22a): undefined reference to `GLShaderManager::~GLShaderManager()'
/tmp/cctwzBOq.o: In function `GLBatch::CopyVertexData3f(float*)':
triangle.cpp:(.text._ZN7GLBatch16CopyVertexData3fEPf[GLBatch::CopyVertexData3f(float*)]+0x1f): undefined reference to `GLBatch::CopyVertexData3f(float (*) [3])'
collect2: ld returned 1 exit status
Also when running a pre-built example of the same source I am experiencing some problems:
Quote:
[hakon@hakon-laptop downloads]$./Triangle
freeglut (./Triangle): ERROR: Internal error <FBConfig with necessary capabilities not found> in function fgOpenWindow
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 4 (X_DestroyWindow)
Resource id in failed request: 0x0
Serial number of failed request: 30
Current serial number in output stream: 33
Segmentation fault
[hakon@hakon-laptop
I am running Crunchbang Linux Statler 64-bit, based on Debian. I have installed the correct nVidia Drivers for my GeForce 9600M GS card. I also have the following packages installed:
- libgl1-nvidia-legacy-96xx-glx(Also the -dev package)
- nvidia-legacy-96xx (Also -dev)
- nvidia-glx-dev
- libglew1.5 (Also -dev)
- libglut3 (Also -dev)
- freeglut3 (Also -dev)

As far as I understand, the freeglut3 packages should replace the libglut3, so I first tried without libglut3, but with the same result. I am also able to run other OpenGL applications like Tremulous and Minecraft.

Some other information:
Quote:
[hakon@hakon-laptop ~]$uname -r
2.6.36-2.dmz.5-liquorix-amd64
[hakon@hakon-laptop ~]$g++ --ver
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
Source code from the book:
Code:
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.

#include <GLTools.h>            // OpenGL toolkit
#include <GLShaderManager.h>    // Shader Manager Class

#ifdef __APPLE__
#include <glut/glut.h>          // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>            // Windows FreeGlut equivalent
#endif

GLBatch	triangleBatch;
GLShaderManager	shaderManager;

///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
    {
	glViewport(0, 0, w, h);
    }


///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context. 
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
	{
	// Blue background
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
    
	shaderManager.InitializeStockShaders();

	// Load up a triangle
	GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 
		                  0.5f, 0.0f, 0.0f,
						  0.0f, 0.5f, 0.0f };

	triangleBatch.Begin(GL_TRIANGLES, 3);
	triangleBatch.CopyVertexData3f(vVerts);
	triangleBatch.End();
	}



///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
	{
	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
	shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
	triangleBatch.Draw();

	// Perform the buffer swap to display back buffer
	glutSwapBuffers();
	}


///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
	{
	gltSetWorkingDirectory(argv[0]);
	
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Triangle");
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(RenderScene);

	GLenum err = glewInit();
	if (GLEW_OK != err) {
		fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
		return 1;
		}
	
	SetupRC();

	glutMainLoop();
	return 0;
	}
I guess it's ok to post it here, it's freely available for download on the homepage for the book.

So, anyone having any ideas on what to do? :)
 
Old 06-28-2011, 07:50 AM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Why are you using the legacy drivers, why not the latest ones ?
 
Old 06-28-2011, 08:10 AM   #3
16pide
Member
 
Registered: Jan 2010
Posts: 418

Rep: Reputation: 83
I had same error on my fedora machine
Code:
undefined reference to `glViewport'
I installed glut dev environment:
Code:
yum install freeglut-devel
in your debian based machine it will be slightly different, but you get the idea.
I also added -lglut as an option to g++
Code:
g++ -lglut triangle.cpp -o triangle
Anyway, now the error is gone.
 
Old 06-28-2011, 08:21 AM   #4
Hvl
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by H_TeXMeX_H View Post
Why are you using the legacy drivers, why not the latest ones ?
Mhm, I think I must have enabled it when I was searching around and trying different packages to solve this problem. Back on the newest drivers now.

Quakeboy02: I allerady have the freeglut-dev packages installed, so I don't think thats the problem.
 
  


Reply



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
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 05:03 AM
mesa, glut and compiling opengl adhara Programming 3 05-08-2004 05:14 AM
Compiling glut applications in Fedora Ross Clement Fedora 3 12-21-2003 12:25 PM
compiling glut? (need help with libMesa) demitasse Linux - Games 2 12-14-2003 11:01 AM
Compiling glut ChimpFace9000 Programming 2 06-01-2002 02:22 PM

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

All times are GMT -5. The time now is 05:22 PM.

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
Open Source Consulting | Domain Registration