Thread: Strange/false errors

  1. #1
    myNegReal
    Join Date
    Jun 2005
    Posts
    100

    Strange/false errors

    I'm pretty sure these errors I'm getting are because of the difference between compilers, but I don't know how to fix it and what to do to what. I'm using Dev-C++. I'm starting out with OpenGL on windows, and when I make a windows app or I use the code from NeHe, it works. But the OpenGL tutorials on this site and at ultimategameprogramming.com, they don't. The problem I'm getting is with CreateWindowEx(). The last parameter, I usually have it set to NULL, which works on my programs and NeHe's, but the other ones, my compiler says this:

    [Warning] passing NULL used for non-pointer converting 1 of `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'

    but I always pass NULL and it works. Why is it having a problem now? After that, I get tons of linker errors saying a bunch of windows functions and OpenGL functions are undefined references (yes, I'm including the headers, and everything is installed).
    Some of these programs are meant for VC++, could that be doing it? Cuz this all works fine when I do it.
    Also, there's programs where functions take float and a call passes for example 1, in my compiler to let it know it's a float it'd have to be 1.f, so I'd fix all that. And then it'd say it can't find that function with the listed parameters, and then list that exact function with the same parameters as a possible candidate. I don't get it. Any ideas? Thanks for any help on this

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Post some simple code that we can compile in Dev-C++ that demonstrates some of the issues.

    gg

  3. #3
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    This is the code for a demo on ultimategameprogramming.com. When I try to run it, I get a warning about passing NULL to the last parameter in CreateWindowEx(), then I get a bunch of linker errors.
    Code:
    #define WIN32_LEAN_AND_MEAN   // This trims down the libraries.
    // #define VC_LEANMEAN not needed in Dev-C++
    
    #include<windows.h>           // The windows header file.
    #include<gl/gl.h>             // Standard opengl include.
    #include<gl/glu.h>            // Opengl utilities.
    #include<gl/glaux.h>          // auxiliary functions.
    
    
    // Function Prototypes
    void RenderScene();
    bool InitializeGL();
    void Shutdown();
    
    
    // Light properties for the diffuse light and specular light.
    float diffuseLight[] = {0.8f, 0.8f, 0.8f, 1.0f};
    float specularLight[] = {1.0f, 1.0f, 1.0f, 1.0f};
    
    // x, y, and z rotation of our object.
    float objectXRot = 0.0f;
    float objectYRot = 0.0f;
    float objectZRot = 0.0f;
    
    // Global device context.
    HDC g_HDC;
    
    
    void SetupPixelFormat(HDC hDC)
    {
       int nPixelFormat;
    
       static PIXELFORMATDESCRIPTOR pfd = {
             sizeof(PIXELFORMATDESCRIPTOR),   // size of structure.
             1,                               // always 1.
             PFD_DRAW_TO_WINDOW |             // support window
             PFD_SUPPORT_OPENGL |             // support OpenGl
             PFD_DOUBLEBUFFER,                // support double buffering
             PFD_TYPE_RGBA,                   // support RGBA
             16,                              // bit color mode
             0, 0, 0, 0, 0, 0,                // ignore color bits
             0,                               // no alpha buffer
             0,                               // ignore shift bit
             0,                               // no accumulation buffer
             0, 0, 0, 0,                      // ignore accumulation bits.
             16,                              // number of depth buffer bits.
             0,                               // number of stencil buffer bits.
             0,                               // 0 means no auxiliary buffer
             PFD_MAIN_PLANE,                  // The main drawing plane
             0,                               // this is reserved
             0, 0, 0 };                       // layer masks ignored.
    
       // This chooses the best pixel format and returns index.
       nPixelFormat = ChoosePixelFormat(hDC, &pfd);
    
       // This set pixel format to device context.
       SetPixelFormat(hDC, nPixelFormat, &pfd);
    }
    
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       static HGLRC hRC;                         // Rendering context.
       static HDC hDC;                           // Device context.
       int width, height;                        // The window width and height.
    	static POINT oldMousePos;                 // Last mouse position.
       static POINT currentMousePos;             // Current mouse position.
       static bool  isMouseActive;               // Is the left mouse button down.
    
    
       switch(message)
          {
             case WM_CREATE:                     // Windows creation.
                hDC = GetDC(hwnd);               // This gets the device context for our window.
                g_HDC = hDC;                     // Assigns the global device context to this one.
                SetupPixelFormat(hDC);           // Call the pixel format function.
    
                hRC = wglCreateContext(hDC);     // Creates the rendering context.
                wglMakeCurrent(hDC, hRC);        // Makes the rendering context.
                return 0;
                break;
    
    
             case WM_CLOSE:                      // Close message.
             case WM_DESTROY:
                wglMakeCurrent(hDC, NULL);
                wglDeleteContext(hRC);           // Deletes the rendering context.
    
                PostQuitMessage(0);              // Says close the program.
                return 0;
                break;
    
    
             case WM_SIZE:                       // re-size message.
                height = HIWORD(lParam);         // This gets the height of the window.
                width = LOWORD(lParam);          // This gets the width of the window.
    
                if(height==0)                    // we don't want it to be possible for a
                   {                             // height of 0.  If it is 0 me make it 1.
                      height = 1;
                   }
    
                glViewport(0, 0, width, height); // resets the viewport to new dimensions.
                glMatrixMode(GL_PROJECTION);     // Sets the projection matrix.
                glLoadIdentity();                // Reset the modelview matrix.
    
                // calculate the aspect ratio of the window.
                gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 1000.0f);
    
                glMatrixMode(GL_MODELVIEW);      // Sets the projection matrix.
                glLoadIdentity();                // Reset the modelview matrix.
    
                return 0;
                break;
    
    
             case WM_KEYDOWN:
    		      switch(wParam)
                   { 
                      // Close the app if the user presses escape.
    		            case VK_ESCAPE:
                         PostQuitMessage(0);
    				         break;
    
                      default:
                         break;
                   }
                break;
    
    
             default:
                break;
          }
       // What this does is pass all of the unhandled messages to DefWindowProc.
       return (DefWindowProc(hwnd, message, wParam, lParam));
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
       MSG msg;                // A message variable.
       WNDCLASSEX windowClass; // Your Window class.
       HWND hwnd;              // The Window handle.
       bool isFinished;        // This will be used to check if the program is done or not.
    
       // This is the Window class.
       windowClass.cbSize = sizeof(WNDCLASSEX);        // size of the WNDCLASSEX structure.
       windowClass.style = CS_HREDRAW | CS_VREDRAW;    // style of the window.
       windowClass.lpfnWndProc = WndProc;              // Address to the windows procedure.
       windowClass.cbClsExtra = 0;                     // Extra class information.
       windowClass.cbWndExtra = 0;                     // Extra window information.
       windowClass.hInstance = hInstance;              // Handle of application Instance.
       // Handle of application Icon.
       windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
       windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);// mouse cursor
       windowClass.hbrBackground = NULL;               // background color.
       windowClass.lpszMenuName = NULL;                // name of the main menu.
       windowClass.lpszClassName = "UltimateGameProgrammingClass";// window class name.
       // icon when minimized.
       windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
       // You must register you class with Windows.
       if(!RegisterClassEx(&windowClass)) return 0;
    
       // Create window...
       hwnd = CreateWindowEx(NULL,// The extended window style.
                            "UltimateGameProgrammingClass",
                            "Lighting - By the Programming Ace.",// window name.
                            WS_OVERLAPPEDWINDOW | WS_VISIBLE |// The window style.
                            WS_SYSMENU | WS_CLIPCHILDREN |// window style.
                            WS_CLIPSIBLINGS,// window style.
                            0, 0,// window x, y coordinate.
                            640, 480,// window width and height.
                            NULL,// handle to parent window.
                            NULL,// menu.
                            hInstance,// handle to app instance.
                            NULL);   // pointer to window creation data.
       
       // If there was an error with creating the window, then close the program.
       if(!hwnd) return 0;
    
       ShowWindow(hwnd, SW_SHOW); // This shows the window.
       UpdateWindow(hwnd);        // This forces a paint message.
    
       isFinished = false;        // False = running, True = not running.
    
       // If initialize fail (return false), then we don't want the program to run.
       if(!InitializeGL()) isFinished = true;
    
       // This is the messsage loop.
       while(!isFinished)
          {
             if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
                {
                   // If a quit message is received then stop rendering and quit the app.
                   if(msg.message == WM_QUIT)
                      {
                         isFinished = true;
                      }
    
                   TranslateMessage(&msg);  // Translate any messages.
                   DispatchMessage(&msg);   // Dispatch any messages.
                }
             else
                {
                   RenderScene();          // Render a frame.
                }
          }
    
       // Shutdown (free) all resources we used up.
       Shutdown();
    
       return (int)msg.wParam;
    }
    
    
    bool InitializeGL()
    {
       glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    
       glShadeModel(GL_SMOOTH);
       glEnable(GL_DEPTH_TEST);   // Enable depth testing.
       glEnable(GL_CULL_FACE);    // Enable culling.
       glFrontFace(GL_CCW);       // Enable counter clockwise culling.
       glEnable(GL_LIGHTING);     // Enable lighting.
    
       // Set up the information for the first light and set it in GL_LIGHT0.
       // We will set the diffuse color and specular color.
       glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
       glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
    
       // Enable the first light source.  We can have up to 8 lights (GL_LIGHT0
       // to GL_LIGHT7).
       glEnable(GL_LIGHT0);
    
       // Set up the material information for our objects.
       // This will allow our objects to have a shininess to it from the light.  Add to the realism.
       // First we enable color material, set up the materials for ambient and diffuse colors,
       // set the color of the specular of the material, then finally set the max amount of shinines.
       // The highest number for the last function is 128 (for the max).
       glEnable(GL_COLOR_MATERIAL);
       glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
       glMaterialfv(GL_FRONT, GL_SPECULAR, specularLight);
       glMateriali(GL_FRONT, GL_SHININESS, 128);
    
       return true;
    }
    
    
    void RenderScene()
    {
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clears the screen.
       glLoadIdentity();                   // Reset modelview matrix for new frame.
    
       // Translate back 5.
       glTranslatef(0.0f, 0.0f, -5.0f);
    
       // Set the color and rotate our object along every axis.
       glColor3f(1.0f, 1.0f, 1.0f);
       glRotatef(objectXRot, 1.0f, 0.0f, 0.0f);
       glRotatef(objectYRot, 0.0f, 1.0f, 0.0f);
       glRotatef(objectZRot, 0.0f, 0.0f, 1.0f);
       
       // Draw the cube using an OpenGL function.
       auxSolidCube(2.0f);
          
       // Increase rotation values to move the object.
       objectXRot += 0.1f;
       objectYRot += 0.2f;
       objectZRot += 0.1f;
    
       SwapBuffers(g_HDC); // Display the new frame.
    }
    
    
    void Shutdown()
    {
    
    }
    // Copyright June 2004
    // All Rights Reserved!
    // Allen Sherrod
    // [email protected]
    // www.UltimateGameProgramming.com
    For the other errors I was talking about, download one of the raytracing demos(except the first one, that works) at ultimategameprogramming.com and put all the files in a project, try to compile it, it'll give those errors

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I get a bunch of linker errors
    This does not help us to help you - you should give explicit examples of some of these errors, or all of them if there aren't too many.

    Still, it seems likely that you haven't linked with the proper opengl libraries (-lopengl32, -lglu32) - dev-cpp has an opengl project template so create one of those and get the project settings from that if you are uncertain about how to include extra libraries.

    The warning about 'NULL' values is not for the last parameter of CreateWindowEx, it's for the first parameter which should be of type DWORD - set it to zero (0) if you don't want extended window styles.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    Ah, I see. Thanks.
    Still, it seems likely that you haven't linked with the proper opengl libraries (-lopengl32, -lglu32) - dev-cpp has an opengl project template
    Yeah, Dev-C++ has OpenGL already installed, so it should be fine, but I did put in GLaux, as I didn't have it, maybe I did not put that one in right.
    Some linker errors:
    [Linker error] undefined reference to `ChoosePixelFormat@8'
    [Linker error] undefined reference to `SetPixelFormat@12'
    [Linker error] undefined reference to `wglCreateContext@4'
    [Linker error] undefined reference to `wglMakeCurrent@8'
    [Linker error] undefined reference to `wglMakeCurrent@8'
    [Linker error] undefined reference to `wglDeleteContext@4'
    [Linker error] undefined reference to `glViewport@16'
    [Linker error] undefined reference to `glMatrixMode@4'
    [Linker error] undefined reference to `glLoadIdentity@0'
    [Linker error] undefined reference to `gluPerspective@32'
    [Linker error] undefined reference to `glMatrixMode@4'
    [Linker error] undefined reference to `glLoadIdentity@0'
    [Linker error] undefined reference to `glClearColor@16'
    [Linker error] undefined reference to `glShadeModel@4'
    [Linker error] undefined reference to `glEnable@4'
    [Linker error] undefined reference to `glEnable@4'
    [Linker error] undefined reference to `glFrontFace@4'
    [Linker error] undefined reference to `glEnable@4'
    [Linker error] undefined reference to `glLightfv@12'
    there's a bunch more glEnable's and glLightfv's
    [Linker error] undefined reference to `glColorMaterial@8'
    [Linker error] undefined reference to `glMaterialfv@12'
    [Linker error] undefined reference to `glMateriali@12'
    [Linker error] undefined reference to `glClear@4'
    [Linker error] undefined reference to `glTranslatef@12'
    [Linker error] undefined reference to `glColor3f@12'
    [Linker error] undefined reference to `glRotatef@16'
    [Linker error] undefined reference to `auxSolidCube@8'
    [Linker error] undefined reference to `SwapBuffers@4'
    Those are most of the linker errors I get, there are a few more, but they are just repeated, so I didn't include them.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You aren't linking the correct libraries as I have previously described; open up dev-cpp, select from the 'file' menu-->new-->project, multimedia tab of the new project dialog-->opengl.

    You can either insert your code into that template or check out the project settings provided with that new, opengl project to ensure that the correct libs are properly linked.
    undefined reference to `ChoosePixelFormat@8'
    ChoosePixelFormat is a gdi function - the libraries of this should be automatically linked if you initially created a windows project.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    1
    I had the same problem as you using the same software
    try this:
    Project , project option (Alt-p)
    Parameter,
    in linking editor field write

    -lglu32
    -lopengl32

    lib/libgdi32.a

    Sorry if the menus are not exactly the same, I have a french version.

  8. #8
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I am constantly getting this/these error/errors:

    no matching function for call to `CLight::CLight(CVector4, int, int, int)'
    candidates are: CLight::CLight(const CLight&)
    CLight::CLight(CVector4&, float, float, float)
    CLight::CLight()

    And I am linking to the libraries.

  9. #9
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Never mind, I re-downloaded some of the glut libraries, and it works now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM