[Linker] error undefined...

This is a discussion on [Linker] error undefined... within the C++ Programming forums, part of the General Programming Boards category; This is my first time writing an openGL file. Im trying to make a Tetris Game using openGL but when ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    4

    [Linker] error undefined...

    This is my first time writing an openGL file. Im trying to make a Tetris Game using openGL but when i try to compile & run i get a bunch of linker errors. now Im not sure which packages I need. I have "freeglut", "glut", "glaux", "glui", "openGlut", and all of the basic packages. I'm really stumped here and could use some help. Here is the program so far it is not complete but it should run but it doesnt due to the linker errors............................

    Code:
    #include <stdio.h>	         // Header File For Standard Input / Output
    #include <stdarg.h>        // Header File For Variable Argument Routines
    #include <string.h>	        // Header File For String Management
    #include <stdlib.h>
    #include <math.h>
    #include <string>
    #include <iostream>
    #include <windows.h>
    //#include <gl/glut.h>
    //#include <GL/freeglut.h>
    //#include <GL/glui.h>
    
    //#include <GL/openglut.h>
    //#include <GL/openglut_exp.h>
    //#include <GL/openglut_ext.h>
    //#include <GL/openglut_std.h>
    
    //#include <GL/glut.h>
    //#include <GL/glutf90.h>
    
    //#include <GL/glaux.h>
    
    #include <GL/freeglut.h>
    #include <GL/freeglut_ext.h>
    #include <GL/freeglut_std.h>
    
    
    using namespace std;
    
    #define FREEGLUT_STATIC
    //#define GLUT_STATIC
    // Constants -----------------------------------------------------------------
    // Height and width of window.  You may wish to change this depending upon
    // your program's needs.
    #define kWindowWidth	800 
    #define kWindowHeight	600
    const double PI = acos(-1.0);
    
    
    // At a depth of -5.0 along the z axis, -2 to 2 ranges over virtually the entire
    // window.
    const double screenDepth = -5.0; 
    const double screenLeftLimit = -2.0;
    const double screenRightLimit = 2.0;
    const double screenUpLimit = 2.0;
    const double screenDownLimit = -2.0;
    const double screenRangeX = 100.0;
    const double screenRangeY = 100.0; 
    
    // Let's make a structure!
    // Structures are fun!
    struct color{
      double rVal;
      double gVal;
      double bVal;     
    }WHITE, BLACK, RED, GREEN, BLUE, MAGENTA, TEAL, YELLOW;
    
    void generateColors(){
      WHITE.rVal = 1.0;  WHITE.gVal = 1.0; WHITE.bVal = 1.0;
      BLACK.rVal = 0.0;  BLACK.gVal = 0.0; BLACK.bVal = 0.0;
      
    }
    
    void setColor(color col){
      glColor3f(col.rVal, col.gVal, col.bVal);
    }
    
    
    void drawNestedQuadz(double x, double y, double xSize, double ySize, 
                         double ratio, color outer, color inner){
      
      double xShift = ratio*xSize;
      double yShift = ratio*ySize;
      
      // Draw 'outer' square
      setColor(outer);
      glBegin(GL_QUADS);
        glVertex2f(x, y);
        glVertex2f(x+xSize, y);
        glVertex2f(x+xSize, y+ySize);
        glVertex2f(x, y+ySize);   
      glEnd();  
      
      setColor(inner);
      glBegin(GL_QUADS);
        glVertex2f(x+xShift, y+yShift);
        glVertex2f(x+xSize-xShift, y+yShift);
        glVertex2f(x+xSize-xShift, y+ySize-yShift);
        glVertex2f(x+xShift, y+ySize-yShift);
      glEnd();
      
    }
    
            
    // TETRIS GLOBAL VARIABLES
    
    bool board[10][20];
    double xSizeBoard = 2.0;
    double ySizeBoard = 4.0;
    double xPositionBoard = -1.0;
    double yPositionBoard = -2.0;
    double boardRatio = .9;
    
    void displayBoard(){
      double xSizeBlock = xSizeBoard/10.0;
      double ySizeBlock = ySizeBoard/20.0;
      
      for(int i=0;i<10;i++){
        for(int j=0;j<20;j++){
           if(board[i][j]){
             drawNestedQuadz(xPositionBoard+i*xSizeBlock, yPositionBoard + j*ySizeBlock,
                               xSizeBlock, ySizeBlock, boardRatio, WHITE, BLACK); 
           }     
        }
      }  
    }
    
     
    double randomPercentage(){
      return (double)(rand()%100)/100.0;
    }
    // Piece Structure
    
       struct piece{
              bool layout[4][4];
              color outerColor;
              color innerColor;
              };
       piece pieces[28];
       void generatePieces(){
            for(int i=0; i< 28; i++){
            for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                pieces[i].layout[j][k] = 0;
                }
                }
            }
            pieces[0].layout[2][3] = 1;
            pieces[0].layout[3][2] = 1;
            pieces[0].layout[3][3] = 1;
            pieces[0].layout[4][3] = 1;
            pieces[0].outerColor = BLACK;
            pieces[0].innerColor = WHITE;
            }
    void addPiece(int reference, int x, int y){
         for(int i=0; i<4;i++){
             for(int j=0; j<4;j++){
             if(pieces[reference].layout[i][j]){
             board[x+i][y+j] =1;
             }
             }
             }
         }
    // Function Prototypes -------------------------------------------------------
    //    Should be included (and later defined) in all programs
    
    GLvoid InitGL(GLvoid);
    GLvoid DrawGLScene(GLvoid);
    GLvoid ReSizeGLScene(int Width, int Height);
    GLvoid Idle(GLvoid);
    GLvoid Keyboard(unsigned char key, int x, int y);
    GLvoid drawText();
    
    
    
    
    // Main ---------------------------------------------------------------------
    //   Drives the good graphics
    
    int main(int argc, char** argv)
    {
        generatePieces();
        addPiece(0, 2, 2);
        addPiece(0, 7, 7);
        addPiece(0, 7, 11);
        // Set up the graphics window
    	glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    	glutInitWindowSize(kWindowWidth, kWindowHeight); 
        glutInitWindowPosition (100, 100);
        glutCreateWindow (argv[0]);
        generateColors();
        
    	// Create the graphics object
    	InitGL();
     
    	// Associate customized functions with the graphics object 
        glutDisplayFunc(DrawGLScene); 
        glutReshapeFunc(ReSizeGLScene);
        glutIdleFunc(Idle);
        glutKeyboardFunc(Keyboard);
        
    	// Start running the graphics object
    	glutMainLoop();
        
        return 0;
    }
    
    // InitGL -------------------------------------------------------------------
    //    You really don't need to worry about this; just make certain to include it
    //    in every program.
    
    GLvoid InitGL(GLvoid)
    {
    	glEnable(GL_TEXTURE_2D);					// Enable Texture Mapping
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);		// This Will Clear The Background Color To Black
    	glClearDepth(1.0);							// Enables Clearing Of The Depth Buffer
    	glDepthFunc(GL_LEQUAL);						// The Type Of Depth Test To Do
    	glEnable(GL_DEPTH_TEST);					// Enables Depth Testing 
    	glShadeModel(GL_SMOOTH);					// Enables Smooth Color Shading
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE);			// Select The Type Of Blending
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();							// Reset The Projection Matrix
    	gluPerspective(45.0f, (GLfloat) kWindowWidth / (GLfloat) kWindowHeight, 0.1f, 100.0f);																				
    	glMatrixMode(GL_MODELVIEW);
    }
    
    // Idle -------------------------------------------------------------------
    //    What the program does if the user does not press any keys
    
    GLvoid Idle(GLvoid)
    {		
    	glutPostRedisplay();
    }
    
    // Keyboard --------------------------------------------------------------
    //   This determines what happens when a button on the keyboard is pressed
    //   or the mouse clicked.  Registers 'key' pressed, or x and y positions
    //   of the mouse click.
    //
    //   You may, at times, wish to modify it.
    
    GLvoid Keyboard(GLubyte key, int x, int y)
    {
    	glutPostRedisplay();    // Current does nothing except redisplay the window
    }
    
    // ReSizeGLScene ------------------------------------------------------------
    //    Don't touch this--this is what happens if the window is resized
    //    (if you grab the lower-right corner and drag)
    //
    
    GLvoid ReSizeGLScene(int Width, int Height)
    {
        glViewport (0, 0, (GLsizei) Width, (GLsizei) Height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0, (GLfloat) Width / (GLfloat) Height, 0.1, 100.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    
    
    // DrawGLScene -----------------------------------------------------
    //    What is drawn every time that the window displays.
    //    This is the only part of the program that you will be editing,
    //    for now.
    
    GLvoid DrawGLScene(GLvoid)
    {    
    	// Don't change this part
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    	glEnable(GL_TEXTURE_2D);                            // Enable texturing
    	glLoadIdentity();									// Reset The View
    	glTranslatef(0.0f,0.0f,-5.0f);						// Move Into The Screen 5 Units
    	
        /* INSERT YOUR PROGRAM HERE */
    	// Draw your scene--this is the part that you will edit 
    	
    	displayBoard();
      
    	/* STOP INSERTING YOUR PROGRAM HERE */
    	
    	// Also critical.  Do not delete.
        glutSwapBuffers();
        glFlush();
    }
    """""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""
    These are my errors"

    [Linker error] undefined reference to `_imp__glutInitDisplayMode@4'
    [Linker error] undefined reference to `_imp__glutInitWindowSize@8'
    [Linker error] undefined reference to `_imp__glutInitWindowPosition@8'
    [Linker error] undefined reference to `_imp__glutCreateWindow@4'
    [Linker error] undefined reference to `_imp__glutDisplayFunc@4'
    [Linker error] undefined reference to `_imp__glutReshapeFunc@4'
    [Linker error] undefined reference to `_imp__glutIdleFunc@4'
    [Linker error] undefined reference to `_imp__glutKeyboardFunc@4'
    [Linker error] undefined reference to `_imp__glutMainLoop@0'
    [Linker error] undefined reference to `_imp__glutPostRedisplay@0'
    [Linker error] undefined reference to `_imp__glutPostRedisplay@0'
    [Linker error] undefined reference to `_imp__glutSwapBuffers@0'
    ld returned 1 exit status

    C:\Documents and Settings\Alejandro Baza\Configuración local\Archivos temporales de Internet\Content.IE5\A49V68XJ\Makefile.win [Build Error] [tetrisBasic[1].exe] Error 1

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Well you need to tell the linker the names and locations of the OpenGL libraries you intent to use.

    If this were on the command line, it might be
    gcc prog.c -lglut

    If you're using some kind of IDE, look for something like
    project settings -> linker -> additional libraries and paths
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    I'm running it on a windows xp pc, and i'm wondering if my computer is even compatible with openGl.

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    do you think I need a different compiler?

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    I think i'm missing something in my parameters, i currently have\

    -lopengl32
    -lglut

    in the parameters. Salem when I added -lglut a few Linker errors went away.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    So it's more of the same, finding out which libraries resolve the symbols outstanding.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21