0

I'm sorry if this is a duplicate question but I've looked through StackOverflow and Google and haven't come up with an answer yet.

I'm using Code::Blocks and SDL and trying to get GLEW working with openGL.

The program code is:

#include <Windows.h>
#include <SDL.h>
#define GLEW_STATIC
#include <glew.h>

int main(int argc, char *argv[])
{
    //initialize SDL
    SDL_Init(SDL_INIT_VIDEO);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

    SDL_Window* window = SDL_CreateWindow("OpenGL", 100, 100, 800, 600, SDL_WINDOW_OPENGL);

    SDL_GLContext context = SDL_GL_CreateContext(window);

    glewExperimental = GL_TRUE;
    glewInit();

    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);

    SDL_GL_DeleteContext(context);
    SDL_Quit();
    return 0;
}

When I build it, it returns:

undefined reference to 'glewExperimental'
undefined reference to 'glewInit@0'
undefined reference to '__glewGenBuffers'

It's not returning an error finding glew.h, so I assume it's a problem with the linker finding the .lib files.

I've added the folder where the .lib files are under Project > Build Options > Search Directories > Linker and added 'glew32s', 'glew32' (I've tried switching the precedence on glew32s and glew32), and 'opengl32' under Linker Settings > Link Libraries, and added '-lglew32s', '-lglew32' (again tried switching the precedence and removing one or the other), and '-lopengl32' under Linker Settings > Other linker options.

I even tried adding the .lib files, .h files, and .dll files to the project folder and adding search directories to the project folder. It still returns the same error.

I'm using the most recent version of glew (1.13.0) on a 64-bit OS. I've tried linking to the 64-bit and 32-bit versions (because I'd read most compilers compile in 32-bit by default for compatibility). Am I linking to the wrong files?

Thanks for reading.

Drew Walbeck
  • 11
  • 1
  • 2
  • I needed to build glew.c myself, and link the resulting glew.o to my program manually, since the lib/dll files didn't work as expected. – tp1 Sep 20 '15 at 23:34
  • I guess you are not using the static libs, but the DLL's libs. – SHR Sep 20 '15 at 23:42
  • I'm not sure about static libs vs. the dll's libs. I downloaded and extracted the files I'm using from the .zip file on the glew sourceforge site http://glew.sourceforge.net/index.html. Are those not the static libs? – Drew Walbeck Sep 21 '15 at 00:55
  • Can you try commenting the `#define GLEW_STATIC` line from the code and see if that helps? – funkysidd Sep 21 '15 at 02:26

0 Answers0