Menu

Strange Linker Error in Dev-C++

Megan B.
2007-11-20
2012-09-26
  • Megan B.

    Megan B. - 2007-11-20

    Hi,

    I've been trying to compile this example for PNG texture mapping in OpenGL that I found here: http://www.wyatt100.freeserve.co.uk/ I'm not even sure what system it was compiled for, but I figured I'd try out the library. I'm having an unusual linker error though, as you will see...because it does not appear to be related to the library, instead it seems to relate to GLUT. Well, here is the information you need:

    (1)I'm working on Windows XP with version 4.9.9.2 of Dev-C++

    (2)Here's the code:

    /
    * Test program for glpng
    * by Ben Wyatt ben@wyatt100.freeserve.co.uk
    * Featuring a shameless plug for my stunt course program
    * Available from the same site as glpng
    * http://www.wyatt100.freeserve.co.uk/download.htm
    /

    include <gl/glpng.h>

    include <gl/glut.h>

    include <stdlib.h>

    int angle = 0;

    /** GLUT callback functions **/

    void KeyPress(unsigned char key, int x, int y) {
    switch (key) {
    case 27: /ESC/ glutDestroyWindow(glutGetWindow()); exit(0); break;
    }
    }

    void Update(void) {
    angle = (angle+1)%360;
    glutPostRedisplay();
    }

    void Display(void) {
    const float w = 2, h = 2;

    glClear(GL_COLOR_BUFFER_BIT);
    
    glLoadIdentity();
    glTranslatef(0, 0, -10);
    glRotatef(angle, 0, 1, 0);
    
    glBegin(GL_QUADS);
        // Front
        glTexCoord2f(1, 1); glVertex3f( w, -h, 0);
        glTexCoord2f(1, 0); glVertex3f( w,  h, 0);
        glTexCoord2f(0, 0); glVertex3f(-w,  h, 0);
        glTexCoord2f(0, 1); glVertex3f(-w, -h, 0);
    
        // Back
        glTexCoord2f(1, 1); glVertex3f(-w, -h, 0);
        glTexCoord2f(1, 0); glVertex3f(-w,  h, 0);
        glTexCoord2f(0, 0); glVertex3f( w,  h, 0);
        glTexCoord2f(0, 1); glVertex3f( w, -h, 0);
    glEnd();
    
    glutSwapBuffers();
    

    }

    void Reshape(int w, int h) {
    glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(30, (float) w/h, 1, 100);
    
    glMatrixMode(GL_MODELVIEW);
    Display();
    

    }

    /** Main function **/

    int main() {
    pngInfo info;
    GLuint texture;

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(300, 300);
    glutCreateWindow(&quot;glpng test&quot;);
    
    #if 0 // Using pngLoad and setting texture parameters manually.
        glGenTextures(1, &amp;texture);
        glBindTexture(GL_TEXTURE_2D, texture);
    
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    
        if (!pngLoad(&quot;Stunt.png&quot;, PNG_NOMIPMAP, PNG_SOLID, &amp;info)) {
            puts(&quot;Can't load file&quot;);
            exit(1);
        }
    #else // Using pngLoadAndBind to set texture parameters automatically.
        texture = pngBind(&quot;Stunt.png&quot;, PNG_NOMIPMAP, PNG_ALPHA, &amp;info, GL_CLAMP, GL_NEAREST, GL_NEAREST);
    
        if (texture == 0) {
            puts(&quot;Can't load file&quot;);
            exit(1);
        }
    #endif
    
    printf(&quot;Size=%i,%i Depth=%i Alpha=%i\n&quot;, info.Width, info.Height, info.Depth, info.Alpha);
    
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);
    glEnable(GL_CULL_FACE);
    glColor3f(1, 1, 1);
    
    glutKeyboardFunc(KeyPress);
    glutIdleFunc(Update);
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    
    glutMainLoop();
    return(0);
    

    }

    (3)It compiles... but doesn't link!:
    Compiler: For GLPNG
    Executing gcc.exe...
    gcc.exe "C:\Documents and Settings\Megan Bednarz\My Documents_School Files!VIZA\PaperDragon\TextureTest_Lars\GLPNGTest\Test.c" -o "C:\Documents and Settings\Megan Bednarz\My Documents_School Files!VIZA\PaperDragon\TextureTest_Lars\GLPNGTest\Test.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -lopengl32 -lglut32 -lglu32
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x1c):Test.c: undefined reference to __glutInitWithExit' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x37):Test.c: undefined reference to__glutCreateWindowWithExit'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x52):Test.c: undefined reference to __glutCreateMenuWithExit' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x70):Test.c: undefined reference toglutGetWindow'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x78):Test.c: undefined reference to glutDestroyWindow' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0xc9):Test.c: undefined reference toglutPostRedisplay'

    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0xed):Test.c: undefined reference to _imp__glClear' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0xf4):Test.c: undefined reference to_impglLoadIdentity'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x115):Test.c: undefined reference to _imp__glTranslatef' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x140):Test.c: undefined reference to_imp
    glRotatef'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x14e):Test.c: undefined reference to _imp__glBegin' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x166):Test.c: undefined reference to_impglTexCoord2f'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x188):Test.c: undefined reference to `_imp
    glVertex3f'

    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x1a0):Test.c: undefined reference to `_imp__glTexCoord2f'

    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x1bd):Test.c: undefined reference to _imp__glVertex3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x1d5):Test.c: undefined reference to_impglTexCoord2f'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x1f7):Test.c: undefined reference to _imp__glVertex3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x20f):Test.c: undefined reference to_imp
    glTexCoord2f'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x236):Test.c: undefined reference to _imp__glVertex3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x24e):Test.c: undefined reference to_impglTexCoord2f'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x275):Test.c: undefined reference to _imp__glVertex3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x28d):Test.c: undefined reference to_imp
    glTexCoord2f'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x2af):Test.c: undefined reference to _imp__glVertex3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x2c7):Test.c: undefined reference to_impglTexCoord2f'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x2e4):Test.c: undefined reference to `_imp
    glVertex3f'

    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x2fc):Test.c: undefined reference to `_imp__glTexCoord2f'

    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x31e):Test.c: undefined reference to _imp__glVertex3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x325):Test.c: undefined reference to_impglEnd'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x32c):Test.c: undefined reference to glutSwapBuffers' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x356):Test.c: undefined reference to_imp
    glViewport'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x364):Test.c: undefined reference to _imp__glMatrixMode' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x36b):Test.c: undefined reference to_impglLoadIdentity'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x397):Test.c: undefined reference to _imp__gluPerspective' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x3a5):Test.c: undefined reference to_imp
    glMatrixMode'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x3e4):Test.c: undefined reference to glutInitDisplayMode' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x3f8):Test.c: undefined reference toglutInitWindowSize'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x43f):Test.c: undefined reference to pngBind' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x494):Test.c: undefined reference to_impglEnable'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x4a9):Test.c: undefined reference to _imp__glBindTexture' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x4b7):Test.c: undefined reference to_imp
    glEnable'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x4d8):Test.c: undefined reference to _imp__glColor3f' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x4e6):Test.c: undefined reference toglutKeyboardFunc'

    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x4f2):Test.c: undefined reference to glutIdleFunc' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x4fe):Test.c: undefined reference toglutDisplayFunc'
    C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x50a):Test.c: undefined reference to glutReshapeFunc' C:\DOCUME~1\MEGANB~1\LOCALS~1\Temp/ccK0baaa.o(.text+0x50f):Test.c: undefined reference toglutMainLoop'
    collect2: ld returned 1 exit status

    Execution terminated

    So, there are the mandatory 3 bits of info. I thought I followed all directions properly, but I am probably missing something very obvious...

    Oh, so the strange part is: these seem to be errors related to GLUT, even though I've been actually using GLUT successfully for other programs I have run. I don't quite remember where I got the GLUT library... probably from opengl.org, so that could be one of the problems. I also might not be linking the png texture mapping header file right, or it could be made wrong and I might have to recompile the source code (oh I don't even want to think about that...at least it comes with source code, though). The download came with an html file of how to use it and where to put all the files. It's part of that Zip file from the website I gave before.

    Okay, I think my brain has had enough... I will turn it over to you guys, the pros. Thanks for all your time in helping me and others with our silly problems! I greatly appreciate any feedback you can give me on these errors.

    --Megan

     
    • Anonymous

      Anonymous - 2007-11-20

      Try changing the link order to:

      -lglut32 -lglu32 -lopengl32

      or use grouping:

      -( -lglut32 -lglu32 -lopengl32 -)

      Link order is significant since by default the linker only makes one pass at each library in the order listed on the command line. A symbol cannot be introduced in a library that is not resolved in the same library or a later one. The linker only carries forward unresolved symbols, not symbols that may or may not be needed by subsequent libraries.

      The grouping solution using -( <library list> -) causes the linker to iterate the group until no further symbols are resolved - it is necessary for libraries with circular dependencies and is otherwise a quick-and-dirty way of not having to figure out the order of dependency. It increases build time which may or may not be significant depending on the size of the project and the order you list the libraries.

      Other than that, you obviously took a look at the "Read First" thread, but failed to observe teh advice about paths containing spaces: "C:\Documents and Settings\Megan Bednarz\My Documents" is not an advisable location for your project. It also apparently reveals your full name, which you may consider a privacy issue.

      Clifford

       
      • Anonymous

        Anonymous - 2007-11-20

        ... and "_School Files"

        Clifford

         
    • Megan B.

      Megan B. - 2007-11-20

      Clifford, thanks for taking a look at this! I'll try the grouping solution if changing the order doesn't work. I tried changing the order before, but I will try it again.

      Good advice on the spaces in filenames... I like to keep my files organized, but having them all in My Documents seems to be a bad decision, at least for these programs.

      Well, I'll try these and see what I come up with!
      Thanks,
      --Megan

       

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.