Original Post
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:
//////////////////////////////////////////////
Here are the warning messages preventing me from compiling.
Building in directory: /home/user/book1/Debug
make
make all-recursive
make[1]: Entering directory
Making all in src
make[2]: Entering directory
CXX main.o
CXXLD book1
main.o: In function
/home/user/book1/src/main.cc:61: undefined reference to
main.o: In function
/home/user/book1/src/main.cc:76: undefined reference to
main.o: In function
/home/user/book1/src/main.cc:90: undefined reference to
/home/user/book1/src/main.cc:92: undefined reference to
/home/user/book1/src/main.cc:94: undefined reference to
/home/user/book1/src/main.cc:106: undefined reference to
/home/user/book1/src/main.cc:33: undefined reference to
/home/user/book1/src/main.cc:34: undefined reference to
main.o: In function
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
make[1]: Leaving directory
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.
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.