*** [block.exe] Error 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flyvin
    New Member
    • Oct 2008
    • 11

    *** [block.exe] Error 1

    I just got the OpenGL SuperBible and wanted to try to compile an example file. At first I got a big list of errors. I added -lopengl32 -lglut32 into Project Options -> Parameters -> Linker. Then all it said was *** [block.exe] Error 1 (bock.exe is my program) I am using Dev C++ 4.9.9.2. Here is the program I am trying to compile.
    Code:
      // Block.cpp
    // OpenGL SuperBible, Chapter 1
    // Demonstrates an assortment of basic 3D concepts
    // Program by Richard S. Wright Jr.
    
    #include "../shared/gltools.h"	// OpenGL toolkit
    #include "../shared/math3d.h"
    #include <math.h>
    
    // Keep track of effects step
    int nStep = 0;
    
    
    // Lighting data
    GLfloat lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
    GLfloat lightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };
    GLfloat lightSpecular[] = { 0.9f, 0.9f, 0.9f };
    GLfloat materialColor[] = { 0.8f, 0.0f, 0.0f };
    GLfloat vLightPos[] = { -80.0f, 120.0f, 100.0f, 0.0f };
    GLfloat ground[3][3] = { { 0.0f, -25.0f, 0.0f },
                            { 10.0f, -25.0f, 0.0f },
                            { 10.0f, -25.0f, -10.0f } };
    
    GLuint textures[4];
    
    
    
    
    
    // Called to draw scene
    void RenderScene(void)
    	{
    	M3DMatrix44f mCubeTransform;
    	M3DVector4f pPlane;
    	
    
    	// Clear the window with current clearing color
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glShadeModel(GL_SMOOTH);
    	glEnable(GL_NORMALIZE);
    
    	glPushMatrix();
    
    	// Draw plane that the cube rests on
    	glDisable(GL_LIGHTING);
    	if(nStep == 5)
    		{
    		glColor3ub(255,255,255);
    		glEnable(GL_TEXTURE_2D);
    		glBindTexture(GL_TEXTURE_2D, textures[0]);
    		glBegin(GL_QUADS);
    			glTexCoord2f(0.0f, 0.0f);
    			glVertex3f(-100.0f, -25.3f, -100.0f);
    			glTexCoord2f(0.0f, 1.0f);
    			glVertex3f(-100.0f, -25.3f, 100.0f);		
    			glTexCoord2f(1.0f, 1.0f);
    			glVertex3f(100.0f,  -25.3f, 100.0f);
    			glTexCoord2f(1.0f, 0.0f);
    			glVertex3f(100.0f,  -25.3f, -100.0f);
    		glEnd();
    		}
    	else
    		{
    		glColor3f(0.0f, 0.0f, 0.90f); // Blue
    		glBegin(GL_QUADS);
    			glVertex3f(-100.0f, -25.3f, -100.0f);
    			glVertex3f(-100.0f, -25.3f, 100.0f);		
    			glVertex3f(100.0f,  -25.3f, 100.0f);
    			glVertex3f(100.0f,  -25.3f, -100.0f);
    		glEnd();
    		}
    
    
    	// Set drawing color to Red
    	glColor3f(1.0f, 0.0f, 0.0f);
    
    	// Enable, disable lighting
    	if(nStep > 2)
    		{
    		glEnable(GL_DEPTH_TEST);
    		glDepthFunc(GL_LEQUAL);
    		glEnable(GL_COLOR_MATERIAL);
    
    		glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
    		glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
    		glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
    		glEnable(GL_LIGHTING);
    		glEnable(GL_LIGHT0);
    		glMaterialfv(GL_FRONT, GL_SPECULAR,lightSpecular);
    		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor);
    		glMateriali(GL_FRONT, GL_SHININESS,128);
    		}
    
    	// Move the cube slightly forward and to the left
    	glTranslatef(-10.0f, 0.0f, 10.0f);
    
    	switch(nStep)
    		{
    		// Just draw the wire framed cube
    		case 0:
    			glutWireCube(50.0f);
    			break;
    
    		// Same wire cube with hidden line removal simulated
    		case 1:
    			// Front Face (before rotation)
    			glBegin(GL_LINES);
    				glVertex3f(25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    				
    				glVertex3f(25.0f,-25.0f,25.0f);
    				glVertex3f(-25.0f,-25.0f,25.0f);
    
    				glVertex3f(-25.0f,-25.0f,25.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    
    				glVertex3f(-25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Top of cube
    			glBegin(GL_LINES);
    				// Front Face
    				glVertex3f(25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glVertex3f(-25.0f,25.0f,-25.0f);
    
    				glVertex3f(-25.0f,25.0f,-25.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    
    				glVertex3f(-25.0f,25.0f,25.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Last two segments for effect
    			glBegin(GL_LINES);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glVertex3f(25.0f,-25.0f,-25.0f);
    
    				glVertex3f(25.0f,-25.0f,-25.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    			glEnd();
    		
    			break;
    
    		// Uniform colored surface, looks 2D and goofey
    		case 2:
    			glutSolidCube(50.0f);
    			break;
    
    		case 3:
    			glutSolidCube(50.0f);
    			break;
    
    		// Draw a shadow with some lighting
    		case 4:
    			glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform);
    			glutSolidCube(50.0f);
    			glPopMatrix();
    
    			// Disable lighting, we'll just draw the shadow as black
    			glDisable(GL_LIGHTING);
    			
    			glPushMatrix();
    
    			m3dGetPlaneEquation(pPlane, ground[0], ground[1], ground[2]);
    			m3dMakePlanarShadowMatrix(mCubeTransform, pPlane, vLightPos);
    			//MakeShadowMatrix(ground, lightpos, cubeXform);
    			glMultMatrixf(mCubeTransform);
    			
    			glTranslatef(-10.0f, 0.0f, 10.0f);			
    			
    			// Set drawing color to Black
    			glColor3f(0.0f, 0.0f, 0.0f);
    
    			glutSolidCube(50.0f);
    			break;
    
    		case 5:
    			glColor3ub(255,255,255);
    			glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform);
    
    			// Front Face (before rotation)
    			glBindTexture(GL_TEXTURE_2D, textures[1]);
    			glBegin(GL_QUADS);
    				glTexCoord2f(1.0f, 1.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    				glTexCoord2f(1.0f, 0.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    				glTexCoord2f(0.0f, 0.0f);
    				glVertex3f(-25.0f,-25.0f,25.0f);
    				glTexCoord2f(0.0f, 1.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Top of cube
    			glBindTexture(GL_TEXTURE_2D, textures[2]);
    			glBegin(GL_QUADS);
    				// Front Face
    				glTexCoord2f(0.0f, 0.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    				glTexCoord2f(1.0f, 0.0f);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glTexCoord2f(1.0f, 1.0f);
    				glVertex3f(-25.0f,25.0f,-25.0f);
    				glTexCoord2f(0.0f, 1.0f);
    				glVertex3f(-25.0f,25.0f,25.0f);
    			glEnd();
    
    			// Last two segments for effect
    			glBindTexture(GL_TEXTURE_2D, textures[3]);
    			glBegin(GL_QUADS);
    				glTexCoord2f(1.0f, 1.0f);
    				glVertex3f(25.0f,25.0f,-25.0f);
    				glTexCoord2f(1.0f, 0.0f);
    				glVertex3f(25.0f,-25.0f,-25.0f);
    				glTexCoord2f(0.0f, 0.0f);
    				glVertex3f(25.0f,-25.0f,25.0f);
    				glTexCoord2f(0.0f, 1.0f);
    				glVertex3f(25.0f,25.0f,25.0f);
    			glEnd();
    		
    
    			glPopMatrix();
    
    			// Disable lighting, we'll just draw the shadow as black
    			glDisable(GL_LIGHTING);
    			glDisable(GL_TEXTURE_2D);
    			
    			glPushMatrix();
    
    			m3dGetPlaneEquation(pPlane, ground[0], ground[1], ground[2]);
    			m3dMakePlanarShadowMatrix(mCubeTransform, pPlane, vLightPos);
    			glMultMatrixf(mCubeTransform);			
    			
    			glTranslatef(-10.0f, 0.0f, 10.0f);			
    			
    			// Set drawing color to Black
    			glColor3f(0.0f, 0.0f, 0.0f);
    			glutSolidCube(50.0f);
    			break;
    			
    		}
    
    	glPopMatrix();
    
    	// Flush drawing commands
    	glutSwapBuffers();
    	}
    
    // This function does any needed initialization on the rendering
    // context. 
    void SetupRC()
    	{
            GLbyte *pBytes;
            GLint nWidth, nHeight, nComponents;
            GLenum format;
    
    	// Black background
    	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
    
            glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
            glGenTextures(4, textures);
            
    	// Load the texture objects
            pBytes = gltLoadTGA("floor.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[0]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
    
    	pBytes = gltLoadTGA("Block4.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[1]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
    
    	pBytes = gltLoadTGA("block5.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[2]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
    
    	pBytes = gltLoadTGA("block6.tga", &nWidth, &nHeight, &nComponents, &format);
            glBindTexture(GL_TEXTURE_2D, textures[3]);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
    		format, GL_UNSIGNED_BYTE, pBytes);
    	free(pBytes);
            }
    
    void KeyPressFunc(unsigned char key, int x, int y)
    	{
    	if(key == 32)
    		{
    		nStep++;
    
    		if(nStep > 5)
    			nStep = 0;
    		}
    
    	// Refresh the Window
    	glutPostRedisplay();
    	}
    
    
    void ChangeSize(int w, int h)
    	{
    	// Calculate new clipping volume
    	GLfloat windowWidth;
    	GLfloat windowHeight;
    
    	// Prevent a divide by zero, when window is too short
    	// (you cant make a window of zero width).
    	if(h == 0)
    		h = 1;
    
    	// Keep the square square
    	if (w <= h) 
    		{
    		windowHeight = 100.0f*(GLfloat)h/(GLfloat)w;
    		windowWidth = 100.0f;
    		}
        else 
    		{
    		windowWidth = 100.0f*(GLfloat)w/(GLfloat)h;
    		windowHeight = 100.0f;
    		}
    
            // Set the viewport to be the entire window
            glViewport(0, 0, w, h);
    
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
    
    	// Set the clipping volume
    	glOrtho(-100.0f, windowWidth, -100.0f, windowHeight, -200.0f, 200.0f);
    
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
    
    	glLightfv(GL_LIGHT0,GL_POSITION, vLightPos);
    
    	glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
    	glRotatef(330.0f, 0.0f, 1.0f, 0.0f);
    	}
    
    int main(int argc, char* argv[])
    	{
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    	glutInitWindowSize(800, 600);
    	glutCreateWindow("3D Effects Demo");
    	glutReshapeFunc(ChangeSize);
    	glutKeyboardFunc(KeyPressFunc);
    	glutDisplayFunc(RenderScene);
    
    	SetupRC();
    
    	glutMainLoop();
    	glDeleteTextures(4,textures);
    	return 0;
    	}
  • arnaudk
    Contributor
    • Sep 2007
    • 425

    #2
    Did you do a "rebuild all"? Incidentally, I think you'd be better off using the free VC++2008 Express if you're working in windows, DevC++ is no longer updated as of 2005. Some people also like CodeBlocks.

    Comment

    • flyvin
      New Member
      • Oct 2008
      • 11

      #3
      I downloaded code blocks(I like open source) and its awesome! Unfortunately, I still have an error. I think I have trouble including gltools.h. Has anyone used this book?

      Comment

      • flyvin
        New Member
        • Oct 2008
        • 11

        #4
        Also, its different errors now. It says it cant find some functions, and there in gltools.h

        Comment

        • arnaudk
          Contributor
          • Sep 2007
          • 425

          #5
          If it can not find functions which are declared in gltools.h at linktime, then you probably haven't linked the correct libraries or the linker can't find then (adjust your paths). Can you can show us the error messages?

          Comment

          • flyvin
            New Member
            • Oct 2008
            • 11

            #6
            Here are my errors. I'm pretty new, and I'm not quite sure how to link a library.
            Code:
            obj\Debug\Block.o(.text+0x3da)||In function `Z11RenderScenev':|
            F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|102|undefined reference to `glutWireCube'|
            obj\Debug\Block.o(.text+0x6d6):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|151|undefined reference to `glutSolidCube'|
            obj\Debug\Block.o(.text+0x6e9):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|155|undefined reference to `glutSolidCube'|
            obj\Debug\Block.o(.text+0x712):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|161|undefined reference to `glutSolidCube'|
            obj\Debug\Block.o(.text+0x74e):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|169|undefined reference to `m3dGetPlaneEquation(float*, float const*, float const*, float const*)'|
            obj\Debug\Block.o(.text+0x768):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|170|undefined reference to `m3dMakePlanarShadowMatrix(float*, float const*, float const*)'|
            obj\Debug\Block.o(.text+0x7c8):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|179|undefined reference to `glutSolidCube'|
            obj\Debug\Block.o(.text+0xb95):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|235|undefined reference to `m3dGetPlaneEquation(float*, float const*, float const*, float const*)'|
            obj\Debug\Block.o(.text+0xbaf):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|236|undefined reference to `m3dMakePlanarShadowMatrix(float*, float const*, float const*)'|
            obj\Debug\Block.o(.text+0xc0f):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|243|undefined reference to `glutSolidCube'|
            obj\Debug\Block.o(.text+0xc19):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|251|undefined reference to `glutSwapBuffers'|
            obj\Debug\Block.o(.text+0xcab)||In function `Z7SetupRCv':|
            F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|269|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
            obj\Debug\Block.o(.text+0xdb4):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|279|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
            obj\Debug\Block.o(.text+0xebd):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|289|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
            obj\Debug\Block.o(.text+0xfc6):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|299|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
            obj\Debug\Block.o(.text+0x10da)||In function `Z12KeyPressFunchii':|
            F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|321|undefined reference to `glutPostRedisplay'|
            obj\Debug\Block.o(.text+0x126c)||In function `main':|
            F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|368|undefined reference to `glutInit'|
            obj\Debug\Block.o(.text+0x1278):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|369|undefined reference to `glutInitDisplayMode'|
            obj\Debug\Block.o(.text+0x128c):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|370|undefined reference to `glutInitWindowSize'|
            obj\Debug\Block.o(.text+0x1298):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|371|undefined reference to `glutCreateWindow'|
            obj\Debug\Block.o(.text+0x12a4):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|372|undefined reference to `glutReshapeFunc'|
            obj\Debug\Block.o(.text+0x12b0):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|373|undefined reference to `glutKeyboardFunc'|
            obj\Debug\Block.o(.text+0x12bc):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|374|undefined reference to `glutDisplayFunc'|
            obj\Debug\Block.o(.text+0x12c6):F:\Documents and Settings\Sam\Desktop\C++ programing\OpenGL\test1\Block.cpp|378|undefined reference to `glutMainLoop'|
            ||=== Build finished: 24 errors, 0 warnings ===|

            Comment

            • flyvin
              New Member
              • Oct 2008
              • 11

              #7
              I found a library file, but I still cant figure out how to link it.

              Comment

              • arnaudk
                Contributor
                • Sep 2007
                • 425

                #8
                The way you link libraries depends on your compiler and IDE. For g++, for example, you can link the libraries opengl32 and glut32 using the command line switches -lopengl32 -lglut32. You need to figure out how to link those relevant libraries in your IDE, have a look through your compiler/IDE reference manual.

                Comment

                • flyvin
                  New Member
                  • Oct 2008
                  • 11

                  #9
                  I have glut and opengl fine, but theres a file called freeglut_static .lib and I think I need it. If its not that, then a I have no idea what to do.

                  Comment

                  • arnaudk
                    Contributor
                    • Sep 2007
                    • 425

                    #10
                    I'm not familiar with the OpenGL Superbible, but if you think you need to link freeglut_static .lib, you can do this in g++ with -lfreeglut_stati c. You might need to tell the compiler where to look for freeglut_static .lib, and you can do this in g++ using the -L switch (see g++ manual online). Have a careful look through the notes that came with your book about compiling the examples, one would think it would not have been taken for granted that you should know how to do this knowing nothing about the libraries that it comes with.

                    Comment

                    Working...