3

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"

5
  • Wild guess: maybe you need to wrap your #include <GL/glew.h> line in extern "C" { ... }?
    – Thomas
    Nov 14, 2012 at 19:21
  • 1
    Also, how are you trying to link it? Including the source files, as per glew.sourceforge.net/install.html, is definitely easier.
    – Thomas
    Nov 14, 2012 at 19:21
  • extern "C" { #include <gl\glew.h> } Nov 14, 2012 at 20:12
  • this is how i'm linking. under codeblocks project build options. tinypic.com/r/fw7xx1/6 Nov 14, 2012 at 20:18
  • For users who are look for the correct linking flag in Ubuntu: -lGLEW.
    – jackw11111
    Aug 11, 2019 at 23:49

3 Answers 3

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.

4
  • 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! Nov 15, 2012 at 0:33
  • i get an undefined reference to winmain whether i declare it statically (like you suggested) or just throw the source file in Nov 15, 2012 at 0: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, 2012 at 1:17
  • SDL. I threw in "#undef main" with all my other preprocessor declarations and it did the trick Nov 15, 2012 at 1: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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.