template boy
template boy

Reputation: 10480

Why am I getting an undefined reference in this code?

I'm using Windows and I'm calling the function glGenBuffers. When I use it I get the following error:

error: undefined reference to _imp____glewBufferData

I'm linking against the glew32 dll that is in my MinGW/lib folder, and I have glew.h inside MinGW/include. I also put the glew32.dll inside the WINDOWS/system32 folder.

I'm compiling like this:

mingw32-g++.exe ... -lglfw -lglfw3 -lopengl32 -lglew32 -lgdi32 -lglu32 -lglew32s

Is it the order of the libraries that's causing the problem? If so, what should come before the other?

Upvotes: 1

Views: 1462

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43369

MinGW does not like the binary dynamic library that ships with glew for Windows, it will only work with Visual C++ unless you do a lot of unnecessarily complicated things to it.

The far simpler solution is to remove -lglew32 from your build commandline, keep -lglew32s (static library) and add -DGLEW_STATIC. The last part is very important because glew assumes dynamic linkage by default when you #include "glew.h". GLEW_STATIC must be defined first for the linker to properly resolve static symbols on Windows.

Upvotes: 3

Related Questions