Menu

[linker error] undefined reference to xxxx

Reeking
2007-11-06
2012-09-26
  • Reeking

    Reeking - 2007-11-06

    what does this error mean?!?! I cant understand it.

    Im using the gl.h, glu.h and windows headers and im trying to replicate the simple rotating triangle thing but I get about 25 of these errors when i try to compile. Infact i htink i get it for every single glXxxx function

     
    • Osito

      Osito - 2007-11-06

      Please read the post titled "PLEASE READ BEFORE POSTING A QUESTION" before posting a question.

       
    • Reeking

      Reeking - 2007-11-06

      Ok...so i deserved to be snarflled or whatever it was...

      Using Dev-C++ version 4.9.8.0

      I'm not sure i could show you a simpler program than the one I'm having problesm with - so I'll copy all the code in making this post probably very very long. I'm working through a book...so i lack the know how to simplify it and replicate the error.

      include <windows.h>

      include <gl/gl.h>

      include <gl/glu.h>

      //Global Variables
      float angle = 0.0f; //Current angle of triangle
      HDC g_HDC; //global device ocntext
      char szClassName[ ] = "WindowsApp"; // Make the class name into a global variable

      //Funciton to set the pixel format
      void SetupPixelFormat(HDC hDC)
      {
      int nPixelFormat; //Pixel format index

      static PIXELFORMATDESCRIPTOR pfd = {
          sizeof(PIXELFORMATDESCRIPTOR),    //Size of structure
          1,                                //version, always set to 1
          PFD_DRAW_TO_WINDOW |                //Support window
          PFD_SUPPORT_OPENGL |                //support opengl
          PFD_DOUBLEBUFFER,                //support double buffering
          PFD_TYPE_RGBA,                        //RGBA color mode
          32,                                //32 bit color mode
          0, 0, 0, 0, 0, 0,                //ignore color bits - not used
          0,                                //No alpha buffer
          0,                                //ignor shift bit
          0,                                //no accumulation buffer
          0, 0, 0, 0,                        //ignore accumulation bits
          16,                                //16bit z-buffer size
          0,                                 //No stencil buffer
          0,                                //no auxilery plane
          PFD_MAIN_PLANE,                   //main drawing plane
          0,                                //reserved
          0, 0, 0 };                        //layer masks ignored
      
      //choose best match
      nPixelFormat = ChoosePixelFormat(hDC, &amp;pfd);
      //set pixel format
      SetPixelFormat(hDC, nPixelFormat, &amp;pfd);
      

      }

      / Declare Windows procedure /
      LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

      int WINAPI WinMain (HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpszArgument,
      int nFunsterStil)

      {
      HWND hwnd; / This is the handle for our window /
      MSG messages; / Here messages to the application are saved /
      WNDCLASSEX wincl; / Data structure for the windowclass /
      bool done;

      /* The Window structure */
      wincl.hInstance = hInstance;
      wincl.lpszClassName = szClassName;
      wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
      wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
      wincl.cbSize = sizeof (WNDCLASSEX);        /* Use default icon and mouse-pointer */
      wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
      wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
      wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
      wincl.lpszMenuName = NULL;                 /* No menu */
      wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
      wincl.cbWndExtra = 0;                      /* structure or the window instance */
      /* Use Windows's default color as the background of the window */
      wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
      
      /* Register the window class, and if it fails quit the program */
      if (!RegisterClassEx (&amp;wincl))
          return 0;
      
      /* The class is registered, let's create the program*/
      hwnd = CreateWindowEx (
             0,                   /* Extended possibilites for variation */
             szClassName,         /* Classname */
             &quot;Windows Application&quot;,       /* Title Text */
             WS_OVERLAPPEDWINDOW, /* default window */
             CW_USEDEFAULT,       /* Windows decides the position */
             CW_USEDEFAULT,       /* where the window ends up on the screen */
             544,                 /* The programs width */
             375,                 /* and height in pixels */
             HWND_DESKTOP,        /* The window is a child-window to desktop */
             NULL,                /* No menu */
             hInstance,       /* Program Instance handler */
             NULL                 /* No Window Creation data */
             );
      
      /* Make the window visible on the screen */
      ShowWindow (hwnd, nFunsterStil);
      UpdateWindow (hwnd);
      
      done = false;
      
      while (!done)
      {
          PeekMessage(&amp;messages, hwnd, 0, 0, PM_REMOVE); //pending message?
          if (messages.message == WM_QUIT)
          {
                  done = true;
          }
          else
          {
                  //do rendering here
                  // clear screen and depth buffer
                  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                  glLoadIdentity();
      
                  angle = angle + 0.1f; //increase your angle
                  if (angle &gt;= 360.0f)
                  {
                          angle = 0.0f;
                  }
                  glTranslatef(0.0f,0.0f,-5.0f);
                  glRotatef(angle, 0.0f, 0.0f, 1.0f);
      
                  glColor3f(1.0f,0.0f,0.0f);
                  glBegin(GL_TRIANGLES);
                          glVertex3f(0.0f,0.0f,0.0f);
                          glVertex3f(1.0f,0.0f,0.0f);
                          glVertex3f(1.0f,1.0f,0.0f);
                  glEnd();
      
                  SwapBuffers(g_HDC);
                  TranslateMessage(&amp;messages); //translate the message
                  DispatchMessage(&amp;messages); //dispatch to windows
          }
      
      }
      
      /* The program return-value is 0 - The value that PostQuitMessage() gave */
      return messages.wParam;
      

      }

      / This function is called by the Windows function DispatchMessage() /

      LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
      {

      static HGLRC hRC; //render Context
      static HDC hDC; //Device Context
      char string[] = &quot;Hello world!&quot;; //Text to be displayed
      int width, height;   //window width and height
      
      switch (message)                  /* handle the messages */
      {
          case WM_CREATE:
                  hDC = GetDC(hwnd);
                  g_HDC = hDC;
                  SetupPixelFormat(hDC);
      
                  //create rendering context
                  hRC = wglCreateContext(hDC);
                  wglMakeCurrent(hDC, hRC);
      
                  return 0;
                  break;
      
          case WM_CLOSE:
                  wglMakeCurrent(hDC, NULL);
                  wglDeleteContext(hRC);
      
                  PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                  return 0;
                  break;
      
          case WM_SIZE:
                  height = HIWORD(lParam); //retreive width and height
                  width = LOWORD(lParam);
      
                  if (height==0)
                  {
                          height = 1;
                  }
      
                  //reset teh viewport
                  glViewport(0, 0, width, height);
                  glMatrixMode(GL_PROJECTION);
                  glLoadIdentity();
      
                  //calculate aspet ratio
                  gluPerspective(45.0f, (GLfloat)width/(GLfloat)height,1.0f,1000.0f);
      
                  glMatrixMode(GL_MODELVIEW);
                  glLoadIdentity();
      
                  return 0;
                  break;
          default:                      /* for messages that we don't deal with */
              return DefWindowProc (hwnd, message, wParam, lParam);
      }
      
      return 0;
      

      }

      Compiler: Default compiler
      Building Makefile: "C:\Dev-Cpp\Projects\WindowsTest2\Makefile.win"
      Executing make...
      make.exe -f "C:\Dev-Cpp\Projects\WindowsTest2\Makefile.win" all
      g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include"

      g++.exe main.o -o "WinTest.exe" -L"C:/Dev-Cpp/lib" -mwindows

      main.o(.text+0x186):main.cpp: undefined reference to glClear@4' main.o(.text+0x18e):main.cpp: undefined reference toglLoadIdentity@0'
      main.o(.text+0x1d6):main.cpp: undefined reference to glTranslatef@12' main.o(.text+0x1ed):main.cpp: undefined reference toglRotatef@16'
      main.o(.text+0x1fe):main.cpp: undefined reference to glColor3f@12' main.o(.text+0x20b):main.cpp: undefined reference toglBegin@4'
      main.o(.text+0x21c):main.cpp: undefined reference to glVertex3f@12' main.o(.text+0x230):main.cpp: undefined reference toglVertex3f@12'
      main.o(.text+0x247):main.cpp: undefined reference to glVertex3f@12' main.o(.text+0x24f):main.cpp: undefined reference toglEnd@0'
      main.o(.text+0x32c):main.cpp: undefined reference to wglCreateContext@4' main.o(.text+0x348):main.cpp: undefined reference towglMakeCurrent@8'
      main.o(.text+0x367):main.cpp: undefined reference to wglMakeCurrent@8' main.o(.text+0x378):main.cpp: undefined reference towglDeleteContext@4'
      main.o(.text+0x3c9):main.cpp: undefined reference to glViewport@16' main.o(.text+0x3d6):main.cpp: undefined reference toglMatrixMode@4'
      main.o(.text+0x3de):main.cpp: undefined reference to glLoadIdentity@0' main.o(.text+0x407):main.cpp: undefined reference togluPerspective@32'
      main.o(.text+0x414):main.cpp: undefined reference to `glMatrixMode@4'

      main.o(.text+0x41c):main.cpp: undefined reference to `glLoadIdentity@0'

      make.exe: *** [WinTest.exe] Error 1

      Execution terminated

       
      • Osito

        Osito - 2007-11-06

        First, I would upgrade to 4.9.9.2. Second, I would re-read the "post before reading" document because some of your issues are covered there. It's not just the basic three that I was looking for - the common problems that newcomers have are also discussed in that post.

         
    • Wayne Keen

      Wayne Keen - 2007-11-06

      Actually, had you read a little farther in that section, you would have seen a section on getting started with Glut, which covers your problem. Please check it out.

      Short version - you failed to link any of the required libraries. There is also a section in that thread on including headers and linking libraries that you might find helpful.

      Wayne

       
      • Wayne Keen

        Wayne Keen - 2007-11-06

        With respect to the snarfled comment, it is my gentle way (using a reference to a movie) of pointing out that you should take a moment or two and check around a forum BEFORE you post your question.

        Not doing so makes more work for the complete strangers you are asking for free help.

        Wayne

         
    • Reeking

      Reeking - 2007-11-06

      I've read teh FAQ - but i really dont get it, I tried going into Project->Project Options but i dunno what to put in the Linker box...

       
      • Wayne Keen

        Wayne Keen - 2007-11-06

        The getting started with Glut directions tell you what to put where - step by step. I suggest you follow the example there in the same way.

        If you have a problem - post something like:

        The directions say to put

        -lglu32

        in the xhyz menu.

        Where is that menu?

        Wayne

         
      • Osito

        Osito - 2007-11-06

        Read it more closely. Pay particular attention to the latter half of this line:

        "In project options, set Type to Win321 GUI and add -lopengl32 -lglut32 -lglu32 to the linker options."

         
    • Wayne Keen

      Wayne Keen - 2007-11-06

      Note that the directions tell you what commands to put in, things like

      -lglut32 -ldiewayne

      ARE linker commands.

       
    • Reeking

      Reeking - 2007-11-06

      Sorted! Thanks for ur patience

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.