Problems with GLEW using MinGW: Undefined reference to '_imp__glewExperimental.'
Asked Answered
S

2

12

I'm using GLEW version 1.10.0 with MinGW (Through the CodeBlocks IDE), running on Windows 8. I downloaded the Windows binaries from the GLEW website, and have been linking to the libraries included with that build.

I have a linking problem that I just can't seem to find an answer to. I have followed the installation on the GLEW home page. I have referenced the linker to the glew32.lib, as well as the other required libs such as opengl32 and glu32.

Unfortunately, compiling this code (I'm also using GLFW for context/window management):

#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#define TRUE 1
#define FALSE 0

int main()
{
GLFWwindow *window;

if (!glfwInit())
    return -1;

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3.0);
window = glfwCreateWindow(640, 480, "Hello World!", NULL, NULL);

if (!window)
{
     glfwTerminate();
     return -1;
}

glfwMakeContextCurrent(window);

// Initialize GLEW
glewExperimental=TRUE;
GLenum err = glewInit();
if (err!=GLEW_OK)
    fprintf(stderr, "Could not initialize GLEW!");

printf("%s\n", glGetString(GL_VERSION));
while (!glfwWindowShouldClose(window))
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);

    glfwSwapBuffers(window);

    glfwPollEvents();
}

glfwTerminate();
return 0;
}

I get the error:

*undefined reference to imp_glewExperimental*

Even though I'm new to C, as far as I understand, this means that I'm referring to something which has no definition, which generally means the library is missing. In this case though, I have included the library, and I got no errors whatsoever about the other GLEW references I make, such as glewInit, which I feel it should also complain about should it be a problem of missing libraries.

I've tried to search the web but I simply haven't found anything on this problem.

Anyone got any ideas? :)

Thank you all very much for your time. It is much appriciated.

Sennacherib answered 29/7, 2013 at 2:35 Comment(0)
S
15

It seems I have solved the problem. For anyone who'd like to know, it appears the problem was the pre-build Windows binaries from the GLEW website, because they originate from Visual Studio (they are .lib files). I was using MinGW to do compilation. As soon as I tried to compile GLEW myself using MinGW to create a .a archive, it worked.

There's already a great answer here on stackoverflow on how to compile GLEW for MinGW, and can be found right here.

Sennacherib answered 30/7, 2013 at 16:16 Comment(3)
Hey! I have an extremely similar problem right now. I compiled GLEW with MinGW using MSYS's make successfully, but still I get some 'not found' messages. Do you by any chance remember your compile/link command or can easily reproduce it? Thanks!Hamilton
I'm having the same issue, g++ -o test.exe test.cpp -I include -L lib -D GLEW_STATIC -lglew32 -lopengl32 gives the same error undefined reference to `glewInit@0'. Am I missing any other libraries that need to be linked?Fulks
Alright it turns out I was using the 32 bit version of MinGW with the 64 bit version of glfw. Changing the PATH variable to the 64 bit version of MinGW fixed it.Fulks
L
0

try to put #define GLEW_STATIC on the first line:

#define GLEW_STATIC
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

and put -lglew32s first in the link libraries table.

codeblocks:

project > build options... > linker settings > add glew32s

then click the up arrow until it get first

Lisalisabet answered 3/1, 2017 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.