1st Triangle program compiles, but doesn't run (with errors) from OPENGL SB5

Started by
1 comment, last by SZupek 12 years ago
I am running through the first OPENGL program in the OPENGL Superbible and I can compile without a problem, but when I got to run the program I get errors

I am using Anjuta 3.2.2

Here is the program code:
//////////////////////////////////////////////

#include <GLTools.h> //OpenGL Toolkit from Book
#include <GLShaderManager.h> //Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/freeglut.h>
#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 project matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
}
//////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// the is the first opportunity to do any OPEN GL related Tasks.
void SetupRC()
{
// Blue Background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
shaderManager.InitializeStockShaders();
// Load up the 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();
} // end SetupRC()
//////////////////////////////////////////////////
// Called to draw the scene
/////////////////////////////////////////////////
void RenderScene(void)
{
// Clear the dinwo with the corrent 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 the back buffer
glutSwapBuffers();
}
////////////////////////////////////////////////
// Main entry point for the 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;
} //end Main loop

Here are the warning messages preventing me from compiling.
Building in directory: /home/user/book1/Debug
make
make all-recursive
make[1]: Entering directory `/home/user/book1/Debug'
make[1]: Entering directory `/home/user/book1/Debug'
Making all in src
make[2]: Entering directory `/home/user/book1/Debug/src'
make[2]: Entering directory `/home/user/book1/Debug/src'
CXX main.o
CXXLD book1
main.o: In function `SetupRC()':
/home/user/book1/src/main.cc:54: undefined reference to `GLShaderManager::InitializeStockShaders()'
/home/user/book1/src/main.cc:61: undefined reference to `GLBatch::Begin(unsigned int, unsigned int, unsigned int)'
/home/user/book1/src/main.cc:63: undefined reference to `GLBatch::End()'
main.o: In function `RenderScene()':
/home/user/book1/src/main.cc:75: undefined reference to `GLShaderManager::UseStockShader(GLT_STOCK_SHADER, ...)'
/home/user/book1/src/main.cc:76: undefined reference to `GLBatch::Draw()'
/home/user/book1/src/main.cc:79: undefined reference to `glutSwapBuffers'
main.o: In function `main':
/home/user/book1/src/main.cc:88: undefined reference to `gltSetWorkingDirectory(char const*)'
/home/user/book1/src/main.cc:90: undefined reference to `glutInit'
/home/user/book1/src/main.cc:91: undefined reference to `glutInitDisplayMode'
/home/user/book1/src/main.cc:92: undefined reference to `glutInitWindowSize'
/home/user/book1/src/main.cc:93: undefined reference to `glutCreateWindow'
/home/user/book1/src/main.cc:94: undefined reference to `glutReshapeFunc'
/home/user/book1/src/main.cc:95: undefined reference to `glutDisplayFunc'
/home/user/book1/src/main.cc:106: undefined reference to `glutMainLoop'
main.o: In function `__static_initialization_and_destruction_0':
/home/user/book1/src/main.cc:33: undefined reference to `GLBatch::GLBatch()'
/home/user/book1/src/main.cc:33: undefined reference to `GLBatch::~GLBatch()'
/home/user/book1/src/main.cc:34: undefined reference to `GLShaderManager::GLShaderManager()'
/home/user/book1/src/main.cc:34: undefined reference to `GLShaderManager::~GLShaderManager()'
main.o: In function `GLBatch::CopyVertexData3f(float*)':
/usr/include/GL/GLBatch.h:89: undefined reference to `GLBatch::CopyVertexData3f(float (*) [3])'
collect2: ld returned 1 exit status
make[2]: *** [book1] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
make[2]: Leaving directory `/home/user/book1/Debug/src'
make[2]: Leaving directory `/home/user/book1/Debug/src'
make[1]: Leaving directory `/home/user/book1/Debug'
make[1]: Leaving directory `/home/user/book1/Debug'
Completed unsuccessfully
Total time taken: 1 secs



It looks like either Anjuta isn't linking to OpenGL or I am missing something rather obvious.

Please help and thank you.

Scott Z.
Advertisement
I believe it is missing a link library, but here are the libraries i have linked

BOOK1 (project name)
-- gl
-- glew
-- glu
---- gl
-- libglfw
I have since switched over to code::blocks for the sake that it appears to be a more user friendly IDE. However, now I am getting a problem in the actual OPENGL code about type mismatch or something along those lines.

Actually it's from math3d.h which is provided by the OpenGL Superbible book (which is for OpenGL version 3+);

||warning: command line option ‘-std=c++0x’ is valid for C++/ObjC++ but not for C [enabled by default]|
/usr/include/math3d.h|148|error: conflicting types for ‘m3dLoadVector2’|
/usr/include/math3d.h|146|note: previous definition of ‘m3dLoadVector2’ was here|
/usr/include/math3d.h|152|error: conflicting types for ‘m3dLoadVector3’|
/usr/include/math3d.h|150|note: previous definition of ‘m3dLoadVector3’ was here|
/usr/include/math3d.h|156|error: conflicting types for ‘m3dLoadVector4’|
/usr/include/math3d.h|154|note: previous definition of ‘m3dLoadVector4’ was here|
/usr/include/math3d.h|163|error: conflicting types for ‘m3dCopyVector2’|
/usr/include/math3d.h|162|note: previous definition of ‘m3dCopyVector2’ was here|
/usr/include/math3d.h|166|error: conflicting types for ‘m3dCopyVector3’|
/usr/include/math3d.h|165|note: previous definition of ‘m3dCopyVector3’ was here|
/usr/include/math3d.h|169|error: conflicting types for ‘m3dCopyVector4’|
||warning: command line option ‘-std=c++0x’ is valid for C++/ObjC++ but not for C [enabled by default]|
/usr/include/math3d.h|148|error: conflicting types for ‘m3dLoadVector2’|
/usr/include/math3d.h|146|note: previous definition of ‘m3dLoadVector2’ was here|
/usr/include/math3d.h|152|error: conflicting types for ‘m3dLoadVector3’|
/usr/include/math3d.h|150|note: previous definition of ‘m3dLoadVector3’ was here|
/usr/include/math3d.h|156|error: conflicting types for ‘m3dLoadVector4’|
/usr/include/math3d.h|154|note: previous definition of ‘m3dLoadVector4’ was here|
/usr/include/math3d.h|163|error: conflicting types for ‘m3dCopyVector2’|
/usr/include/math3d.h|162|note: previous definition of ‘m3dCopyVector2’ was here|
/usr/include/math3d.h|166|error: conflicting types for ‘m3dCopyVector3’|
/usr/include/math3d.h|165|note: previous definition of ‘m3dCopyVector3’ was here|
/usr/include/math3d.h|169|error: conflicting types for ‘m3dCopyVector4’|
/usr/include/math3d.h|168|note: previous definition of ‘m3dCopyVector4’ was here|
/usr/include/math3d.h|176|error: conflicting types for ‘m3dAddVectors2’|
/usr/include/math3d.h|174|note: previous definition of ‘m3dAddVectors2’ was here|
/usr/include/math3d.h|181|error: conflicting types for ‘m3dAddVectors3’|
/usr/include/math3d.h|179|note: previous definition of ‘m3dAddVectors3’ was here|
/usr/include/math3d.h|186|error: conflicting types for ‘m3dAddVectors4’|
/usr/include/math3d.h|184|note: previous definition of ‘m3dAddVectors4’ was here|
/usr/include/math3d.h|193|error: conflicting types for ‘m3dSubtractVectors2’|
/usr/include/math3d.h|191|note: previous definition of ‘m3dSubtractVectors2’ was here|
/usr/include/math3d.h|198|error: conflicting types for ‘m3dSubtractVectors3’|
/usr/include/math3d.h|196|note: previous definition of ‘m3dSubtractVectors3’ was here|
/usr/include/math3d.h|203|error: conflicting types for ‘m3dSubtractVectors4’|
/usr/include/math3d.h|201|note: previous definition of ‘m3dSubtractVectors4’ was here|
/usr/include/math3d.h|212|error: conflicting types for ‘m3dScaleVector2’|
/usr/include/math3d.h|210|note: previous definition of ‘m3dScaleVector2’ was here|
/usr/include/math3d.h|217|error: conflicting types for ‘m3dScaleVector3’|
/usr/include/math3d.h|215|note: previous definition of ‘m3dScaleVector3’ was here|
/usr/include/math3d.h|222|error: conflicting types for ‘m3dScaleVector4’|
/usr/include/math3d.h|220|note: previous definition of ‘m3dScaleVector4’ was here|
/usr/include/math3d.h|237|error: conflicting types for ‘m3dCrossProduct3’|
/usr/include/math3d.h|230|note: previous definition of ‘m3dCrossProduct3’ was here|
/usr/include/math3d.h|250|error: conflicting types for ‘m3dDotProduct3’|
/usr/include/math3d.h|247|note: previous definition of ‘m3dDotProduct3’ was here|
/usr/include/math3d.h||In function ‘m3dGetAngleBetweenVectors3’:|
/usr/include/math3d.h|258|error: expected expression before ‘float’|
/usr/include/math3d.h|261|error: conflicting types for ‘m3dGetAngleBetweenVectors3’|
/usr/include/math3d.h|255|note: previous definition of ‘m3dGetAngleBetweenVectors3’ was here|
/usr/include/math3d.h|273|error: conflicting types for ‘m3dGetVectorLengthSquared3’|
/usr/include/math3d.h|270|note: previous definition of ‘m3dGetVectorLengthSquared3’ was here|
/usr/include/math3d.h|282|error: conflicting types for ‘m3dGetVectorLength3’|
/usr/include/math3d.h|279|note: previous definition of ‘m3dGetVectorLength3’ was here|
/usr/include/math3d.h|291|error: conflicting types for ‘m3dNormalizeVector3’|
/usr/include/math3d.h|288|note: previous definition of ‘m3dNormalizeVector3’ was here|
/usr/include/math3d.h|300|error: conflicting types for ‘m3dGetDistanceSquared3’|
/usr/include/math3d.h|299|note: previous declaration of ‘m3dGetDistanceSquared3’ was here|
/usr/include/math3d.h|305|error: conflicting types for ‘m3dGetDistance3’|
/usr/include/math3d.h|302|note: previous definition of ‘m3dGetDistance3’ was here|
/usr/include/math3d.h|309|error: conflicting types for ‘m3dGetMagnitudeSquared3’|
/usr/include/math3d.h|308|note: previous definition of ‘m3dGetMagnitudeSquared3’ was here|
/usr/include/math3d.h|312|error: conflicting types for ‘m3dGetMagnitude3’|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 1 warnings ===|
/usr/include/math3d.h|168|note: previous definition of ‘m3dCopyVector4’ was here|
/usr/include/math3d.h|176|error: conflicting types for ‘m3dAddVectors2’|
/usr/include/math3d.h|174|note: previous definition of ‘m3dAddVectors2’ was here|
/usr/include/math3d.h|181|error: conflicting types for ‘m3dAddVectors3’|
/usr/include/math3d.h|179|note: previous definition of ‘m3dAddVectors3’ was here|
/usr/include/math3d.h|186|error: conflicting types for ‘m3dAddVectors4’|
/usr/include/math3d.h|184|note: previous definition of ‘m3dAddVectors4’ was here|
/usr/include/math3d.h|193|error: conflicting types for ‘m3dSubtractVectors2’|
/usr/include/math3d.h|191|note: previous definition of ‘m3dSubtractVectors2’ was here|
/usr/include/math3d.h|198|error: conflicting types for ‘m3dSubtractVectors3’|
/usr/include/math3d.h|196|note: previous definition of ‘m3dSubtractVectors3’ was here|
/usr/include/math3d.h|203|error: conflicting types for ‘m3dSubtractVectors4’|
/usr/include/math3d.h|201|note: previous definition of ‘m3dSubtractVectors4’ was here|
/usr/include/math3d.h|212|error: conflicting types for ‘m3dScaleVector2’|
/usr/include/math3d.h|210|note: previous definition of ‘m3dScaleVector2’ was here|
/usr/include/math3d.h|217|error: conflicting types for ‘m3dScaleVector3’|
/usr/include/math3d.h|215|note: previous definition of ‘m3dScaleVector3’ was here|
/usr/include/math3d.h|222|error: conflicting types for ‘m3dScaleVector4’|
/usr/include/math3d.h|220|note: previous definition of ‘m3dScaleVector4’ was here|
/usr/include/math3d.h|237|error: conflicting types for ‘m3dCrossProduct3’|
/usr/include/math3d.h|230|note: previous definition of ‘m3dCrossProduct3’ was here|
/usr/include/math3d.h|250|error: conflicting types for ‘m3dDotProduct3’|
/usr/include/math3d.h|247|note: previous definition of ‘m3dDotProduct3’ was here|
/usr/include/math3d.h||In function ‘m3dGetAngleBetweenVectors3’:|
/usr/include/math3d.h|258|error: expected expression before ‘float’|
/usr/include/math3d.h|261|error: conflicting types for ‘m3dGetAngleBetweenVectors3’|
/usr/include/math3d.h|255|note: previous definition of ‘m3dGetAngleBetweenVectors3’ was here|
/usr/include/math3d.h|273|error: conflicting types for ‘m3dGetVectorLengthSquared3’|
/usr/include/math3d.h|270|note: previous definition of ‘m3dGetVectorLengthSquared3’ was here|
/usr/include/math3d.h|282|error: conflicting types for ‘m3dGetVectorLength3’|
/usr/include/math3d.h|279|note: previous definition of ‘m3dGetVectorLength3’ was here|
/usr/include/math3d.h|291|error: conflicting types for ‘m3dNormalizeVector3’|
/usr/include/math3d.h|288|note: previous definition of ‘m3dNormalizeVector3’ was here|
/usr/include/math3d.h|300|error: conflicting types for ‘m3dGetDistanceSquared3’|
/usr/include/math3d.h|299|note: previous declaration of ‘m3dGetDistanceSquared3’ was here|
/usr/include/math3d.h|305|error: conflicting types for ‘m3dGetDistance3’|
/usr/include/math3d.h|302|note: previous definition of ‘m3dGetDistance3’ was here|
/usr/include/math3d.h|309|error: conflicting types for ‘m3dGetMagnitudeSquared3’|
/usr/include/math3d.h|308|note: previous definition of ‘m3dGetMagnitudeSquared3’ was here|
/usr/include/math3d.h|312|error: conflicting types for ‘m3dGetMagnitude3’|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 1 warnings ===|



And it's crying about this OPENGL code
inline void m3dLoadVector2(M3DVector2d v, const float x, const float y)

LINE 148 in math3d.h

Any idea? The code came straight from the book/cd

This topic is closed to new replies.

Advertisement