glew linking problems

Hi all, I'm new here. So forgive me if this is obvious, but I've been struggling for hours on this today!

PROBLEM
I'm following an SDL/OpenGL tutorial on Youtube (https://www.youtube.com/watch?v=8t3m2mRH7qs). I'm trying to get my project to compile, but I'm getting errors such as the ones listed below. I'm 99% sure this is a linker issue.

ERRORS
undefined reference to 'glClearColor@16'
undefined reference to 'glClearDepth@8'
undefined reference to 'glClear@4'
undefined reference to 'glClearDepth@8'
undefined reference to 'glClear@4'

VERSIONS AND COMPUTER SPECS
IDE: Code Blocks 16.0.1
SDL: SDL2-2.0.4
GLEW: glew-1.13.0
Operating System: Windows 7

LINKING:
glew32s.lib
glew32.lib.
libSDL2.a
libSDL2main.a
libSDL2.dll.a.

In Build Options I put this in "Other linker options:"
-lmingw32 -lSDL2main -lSDL2

... tried adding -lglew32, -lglew32s, and all variations of those I could think of to no avail.

INCLUDING
glew.h
SDL.h

COMPILER
GNU GCC Compiler

SOLUTIONS I'VE TRIED
* Adding "#define GLEW_STATIC" to the top of my MainGame.h header file.
* Making sure that glew32s.lib is at the top of my list of linked libraries
* (Repeat of above) Tried adding -lglew32, -lglew32s, and all variations of those I could think of to the linker options... but to no avail.
* Made sure "Search Directories" was pointing to both the include and lib folders for GL.

Please help me. As a robotics professor once told me, "If you get stuck on something, don't struggle. Stand on the shoulders of giants-- your fellow programmers."
It is likely that you're missing "opengl32.lib" in your linking.
AcarX, after 2 hours of searching/experimenting this morning, I read somewhere that OpenGL is built into most operating systems. So I started a new project in Code Blocks and chose the OpenGL template. Turns out this project template automatically has "openGL32" in its linker list.

So... I thought, "Weird. Where is that coming from?" I went into the MinGW directory and saw in MinGW/lib a library called libopengl32.a. Then I remembered what you said. So i went back to my project that I built from scratch (NOT templated for OpenGL), linked that library, and voila! It worked!

So... You helped me. Thanks. You gave me a fish-- now can you teach me how to fish for myself by telling me how you knew it was opengl32.lib I was missing?

Thanks again!
Michael
closed account (E0p9LyTq)
The most common reason for undefined references to library functions is a missing .lib file in the linker list.
^ Pretty much. Take this example for example:

1
2
3
4
5
6
7
void someFunc();

int main()
{
    someFunc();
    return 0;
}


This will give you the same error with the name 'someFunc' instead of 'gl*'. So whenever you get this error you should make sure compiler knows where the function is defined, in this case 'opengl32.lib'.
closed account (E0p9LyTq)
@AcarX,

Your example is a user-defined function, not a library function. ;)

In either example the compiler can't find the object code for the function, so same undefined error.

Oh, the number of times I have been stumped by that undefined error, user-defined functions or from a library! :D
Topic archived. No new replies allowed.