Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Issue compiling OpenGL program that uses GLEW

  1. #1
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    5

    Issue compiling OpenGL program that uses GLEW

    Hi all,
    This is my first post here. I've been learning C++, SDL, and OpenGL the last few weeks and finally ran into a problem I can't seem to get around.
    I'm using Code::Blocks in Windows 7.
    I was able to set up OpenGL, install freeglut, etc. The sample program that CB gives compiles and works fine.

    I then started to go through some tutorials. The first one worked fine (which was opening an OpenGL window), but when I got to the second, where it puts a dot on the screen, it started using glew.h.

    Whenever I compile the code they have:

    Code :
    #include <stdio.h>
    #include <GL/glew.h>
    #include <GL/freeglut.h>
    #include "math_3d.h"
     
    GLuint VBO;
     
    static void RenderSceneCB()
    {
        glClear(GL_COLOR_BUFFER_BIT);
     
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
     
        glDrawArrays(GL_POINTS, 0, 1);
     
        glDisableVertexAttribArray(0);
     
        glutSwapBuffers();
    }
     
     
    static void InitializeGlutCallbacks()
    {
        glutDisplayFunc(RenderSceneCB);
    }
     
    static void CreateVertexBuffer()
    {
        Vector3f Vertices[1];
        Vertices[0] = Vector3f(0.0f, 0.0f, 0.0f);
     
     	glGenBuffers(1, &VBO);
    	glBindBuffer(GL_ARRAY_BUFFER, VBO);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
    }
     
     
    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
        glutInitWindowSize(1024, 768);
        glutInitWindowPosition(100, 100);
        glutCreateWindow("Tutorial 02");
     
        InitializeGlutCallbacks();
     
        // Must be done after glut is initialized!
        GLenum res = glewInit();
        if (res != GLEW_OK) {
          fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
          return 1;
        }
     
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     
        CreateVertexBuffer();
     
        glutMainLoop();
     
        return 0;
    }

    I keep getting the following error:


    Code :
    obj\Debug\main.o||In function `RenderSceneCB':|
    C:\C Programs\OpenGL Test\main.cpp|33|undefined reference to `_imp____glewEnableVertexAttribArray'|
    C:\C Programs\OpenGL Test\main.cpp|34|undefined reference to `_imp____glewBindBuffer'|
    C:\C Programs\OpenGL Test\main.cpp|35|undefined reference to `_imp____glewVertexAttribPointer'|
    C:\C Programs\OpenGL Test\main.cpp|39|undefined reference to `_imp____glewDisableVertexAttribArray'|
    obj\Debug\main.o||In function `CreateVertexBuffer':|
    C:\C Programs\OpenGL Test\main.cpp|55|undefined reference to `_imp____glewGenBuffers'|
    C:\C Programs\OpenGL Test\main.cpp|56|undefined reference to `_imp____glewBindBuffer'|
    C:\C Programs\OpenGL Test\main.cpp|57|undefined reference to `_imp____glewBufferData'|
    obj\Debug\main.o||In function `main':|
    C:\C Programs\OpenGL Test\main.cpp|72|undefined reference to `_imp__glewInit'|
    C:\C Programs\OpenGL Test\main.cpp|74|undefined reference to `_imp__glewGetErrorString'|
    ||=== Build finished: 9 errors, 0 warnings (0 minutes, 0 seconds) ===|

    (Note, the last two errors about glewInit and glewGetErrorString have more characters on the ends of them, but I can't post it like that since I get an error about URLs.)

    I've done several internet searches and it seems most people that get the errors are able to solve them in ways that don't pertain to me (such as leaving out a header file, etc.)
    I'm stumped and am unable to go any further.
    If anyone could give some insight how to to get past this, I'd appreciate it!
    Last edited by MilesAway1980; 05-22-2013 at 03:12 PM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    You have not included the glew library in your link

  3. #3
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    5
    Thanks for the reply.

    I missed including the glew32 library in the linker and added it. However, it only decreased the number of errors from 9 to 7.
    Tried a bunch of tutorials on line and have messed around with including different libraries to see if I was leaving anything out. Not much is changing.

    The error message still reads:

    Code :
    obj\Debug\main.o||In function `RenderSceneCB':|
    C:\C Programs\OpenGL Test\main.cpp|12|undefined reference to `_imp____glewEnableVertexAttribArray'|
    C:\C Programs\OpenGL Test\main.cpp|13|undefined reference to `_imp____glewBindBuffer'|
    C:\C Programs\OpenGL Test\main.cpp|14|undefined reference to `_imp____glewVertexAttribPointer'|
    C:\C Programs\OpenGL Test\main.cpp|18|undefined reference to `_imp____glewDisableVertexAttribArray'|
    obj\Debug\main.o||In function `CreateVertexBuffer':|
    C:\C Programs\OpenGL Test\main.cpp|34|undefined reference to `_imp____glewGenBuffers'|
    C:\C Programs\OpenGL Test\main.cpp|35|undefined reference to `_imp____glewBindBuffer'|
    C:\C Programs\OpenGL Test\main.cpp|36|undefined reference to `_imp____glewBufferData'|
    ||=== Build finished: 7 errors, 0 warnings (0 minutes, 0 seconds) ===|

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    Try building with GLEW_STATIC compile option to link static library

  5. #5
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    5
    Hrmmm... That was one of the things I already tried (and is still set right now). It didn't make any difference. Unless, I did it incorrectly. I have "GLEW_STATIC" under the compiler #defines in Code::Blocks.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    I don't use Code::Blocks so can't help there. Here are the relevant lines from my VS2008 test
    Code :
    PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;FREEGLUT_STATIC;FREEGLUT_LIB_PRAGMAS;GLEW_STATIC"
    AdditionalDependencies="OpenGL32.lib freeglut_static.lib glew_static.lib"

    This linked your code with no problems

  7. #7
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    5
    The glew-1.9.0 package that I downloaded didn't include a glew_static.lib, could that be an issue?
    Last edited by MilesAway1980; 05-26-2013 at 08:25 AM.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    No, that is just the name I used for my copy of the static library. I think the original is called glew32s.lib and glew32sd.lib for debug.

  9. #9
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    5
    Oh okay. I tried including the glew32s and glew32sd libraries before with no change in results.

    Thanks for everyone's help, but honestly, I'm almost no closer to solving this than I was when I started.
    I have no idea how to get this working or what I'm doing wrong.

  10. #10
    Newbie Newbie
    Join Date
    Jun 2013
    Posts
    3
    I'm having a similar, if not an exact same, issue as Miles. I'm on chapter 2 of openglbook.com.

    Here's the build log

    Code :
    ------------ Clean: Debug in 40 (compiler: GNU GCC Compiler)---------------
     
    Cleaned "40 - Debug"
     
    -------------- Build: Debug in 40 (compiler: GNU GCC Compiler)---------------
     
    mingw32-g++.exe -Wall  -g    -ID:\backup\funstuff\programming\freeglut\include  -c D:\backup\funstuff\programming\40\main.cpp -o obj\Debug\main.o
    mingw32-g++.exe  -o bin\Debug\40.exe obj\Debug\main.o    -lglew32 -lfreeglut -lopengl32

    And my headers.

    Code :
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <GL/glew.h>
    #include <GL/freeglut.h>
    #define WINDOW_TITLE_PREFIX "Chapter 2"
    #define GLEW_STATIC

    I've even put GLEW_STATIC before glew.h and had the same outcome.

    I'm not too sure about static and dynamic linking. Does that solely rest on whether I use glew32.lib or glew32s.lib? Or should they be in my compiler linker settings vs. my project linker settings?

    Using win7 X64 with Code::Blocks and mingw/GCC compiler and fresh installs less than a week ago btw.

    I know the error has something to do with the linkers cause I had to figure out that I was accidentally using the 64 bit of glew with 32 bit freeglut and opengl32. Which caused similar issues.

    What am I doing wrong?
    Last edited by Sramos58; 06-20-2013 at 07:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •