I've recently made the decision to re-write some OpenGL code for a game using im working on using non depreciated techniques. Instead of drawing primitives with glBegin() and glEnd(), i'm trying to stick to vertex array objects and such. I'm trying to get code to compile from http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/ . I've done alot of linking before but for some reason this isn't working. I'm trying to link GLEW to my project with CodeBlocks as my IDE and MinGW GCC as my compiler. How do I go about fixing this? Yes, i did link "glew32.lib"
Asked
Active
Viewed 1.6k times
3

Nicol Bolas
- 449,505
- 63
- 781
- 982

agusterodin
- 417
- 1
- 5
- 17
-
Wild guess: maybe you need to wrap your `#include
` line in `extern "C" { ... }`? – Thomas Nov 14 '12 at 19:21 -
1Also, how are you trying to link it? Including the source files, as per http://glew.sourceforge.net/install.html, is definitely easier. – Thomas Nov 14 '12 at 19:21
-
extern "C" { #include
} – agusterodin Nov 14 '12 at 20:12 -
this is how i'm linking. under codeblocks project build options. http://tinypic.com/r/fw7xx1/6 – agusterodin Nov 14 '12 at 20:18
-
For users who are look for the correct linking flag in Ubuntu: `-lGLEW`. – jackw11111 Aug 11 '19 at 23:49
3 Answers
7
This usually happens if you link GLEW statically, but don't inform the header about this to happen. For this you must define the preprocessor token "GLEW_STATIC". This is best done as a compiler option. In case of GCC, add -DGLEW_STATIC
to your compiler command line.

datenwolf
- 159,371
- 13
- 185
- 298
-
that worked! thanks. ultimately i decided to just throw the source file for GLEW (glew.c). Now, however, i am getting undefined reference to `WinMain@16'. Kill me now! – agusterodin Nov 15 '12 at 00:33
-
i get an undefined reference to winmain whether i declare it statically (like you suggested) or just throw the source file in – agusterodin Nov 15 '12 at 00:35
-
@user1575273: What framework are you using? WinMain is the process entry function for regular Windows executables. You can use regular main as well, but this requires some adjustments to the linking options. – datenwolf Nov 15 '12 at 01:17
-
SDL. I threw in "#undef main" with all my other preprocessor declarations and it did the trick – agusterodin Nov 15 '12 at 01:23
1
Try this:
pkg-config --libs --static glew
in the terminal. Then, copy the libs it gives you and paste after your gcc/g++ statement:
g++ <your-file-name>.cpp -o <output-file-name> -lGL -lGLU -lglfw3 -lrt -lm -ldl -lXrandr -lXinerama -lXcursor -lXext -lXrender -lXfixes -lX11 -lpthread -lxcb -lXau -lXdmcp -lGLEW -lGLU -lGL -lm -ldl -ldrm -lXdamage -lX11-xcb -lxcb-glx -lxcb-dri2 -lxcb-dri3 -lxcb-present -lxcb-sync -lxshmfence -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp
(some are repeated above because I used glfw too)
This is supposed to solve your problem, because usually these libraries are not declared.

redharpoonprog
- 11
- 3
0
If you use Linux, FLTK ui library with OpenGL, see .../bin/fltk-config file for LDLIBS. It should contain also "-lGLEW" or you can add this option to the LDLIBS parameter when compile. Of course "libglew-dev" should be installed.

Alex
- 1,297
- 1
- 16
- 12