Author Topic: Hard broblems with linking GLEW library  (Read 18152 times)

Offline Kolcebruevsky

  • Single posting newcomer
  • *
  • Posts: 3
Hard broblems with linking GLEW library
« on: June 29, 2011, 10:15:48 am »
Hello C::B forum!
I have a big problem with linking GLEW library. I'm working on Windows 32bit platform, using C::B with GCC. I downloaded GLEW 1.6.0 library binaries from glew.sourceforge.net. When i try compile the project i'm having more linking errors like this "undefined reference ... ".

I'm included this stuff:

Linker settings:
Link libraries:
gdi32
winmm
glew32
opengl32
glu32

Search directories:
Compiler:
D:\glew\include

Linker:
D:\glew\lib

I'm trying use GLEW in static and dynamic mode but problem not solved. I'm read many solutions for this problem but problem not solved... And all GLEW extensions is ignored. So where i can find GLEW library for GCC with all extensions? Please help.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Kolcebruevsky

  • Single posting newcomer
  • *
  • Posts: 3
Re: Hard broblems with linking GLEW library
« Reply #2 on: June 29, 2011, 03:48:08 pm »
This is log of my errors. How to fix it?

Linker:
libopengl32.a
glut32.lib
glew32.lib
glew32mx.lib

Code
Build started on: 29-06-2011 at 17:42.04
 Build ended on: 29-06-2011 at 17:42.05

-------------- Build: Debug in Test ---------------
 Linking console executable: bin\Debug\Test.exe
 obj\Debug\Test.o: In function `Z16checkOpenGLErrorv':
G:/Hlp/Glee/Test.cpp:42: undefined reference to `gluErrorString@4'
 obj\Debug\Test.o: In function `Z12printInfoLogj':
G:/Hlp/Glee/Test.cpp:59: undefined reference to `_imp____glewGetObjectParameterivARB'
G:/Hlp/Glee/Test.cpp:75: undefined reference to `_imp____glewGetInfoLogARB'
 obj\Debug\Test.o: In function `Z10loadShaderjPKc':
G:/Hlp/Glee/Test.cpp:123: undefined reference to `_imp____glewShaderSourceARB'
G:/Hlp/Glee/Test.cpp:127: undefined reference to `_imp____glewCompileShaderARB'
G:/Hlp/Glee/Test.cpp:132: undefined reference to `_imp____glewGetObjectParameterivARB'
 obj\Debug\Test.o: In function `Z16setUniformVectorjPKcPKf':
G:/Hlp/Glee/Test.cpp:140: undefined reference to `_imp____glewGetUniformLocationARB'
G:/Hlp/Glee/Test.cpp:145: undefined reference to `_imp____glewUniform4fvARB'
 obj\Debug\Test.o: In function `Z7displayv':
G:/Hlp/Glee/Test.cpp:180: undefined reference to `_imp____glewUseProgramObjectARB'
G:/Hlp/Glee/Test.cpp:184: undefined reference to `_imp____glewUseProgramObjectARB'
 obj\Debug\Test.o: In function `Z7reshapeii':
G:/Hlp/Glee/Test.cpp:197: undefined reference to `gluPerspective@32'
G:/Hlp/Glee/Test.cpp:200: undefined reference to `gluLookAt@72'
 obj\Debug\Test.o: In function `Z7animatev':
G:/Hlp/Glee/Test.cpp:248: undefined reference to `_imp____glewUseProgramObjectARB'
G:/Hlp/Glee/Test.cpp:251: undefined reference to `_imp____glewUseProgramObjectARB'
 obj\Debug\Test.o: In function `main':
G:/Hlp/Glee/Test.cpp:284: undefined reference to `_imp____GLEW_ARB_shading_language_100'
G:/Hlp/Glee/Test.cpp:291: undefined reference to `_imp____GLEW_ARB_shader_objects'
G:/Hlp/Glee/Test.cpp:301: undefined reference to `_imp____glewCreateShaderObjectARB'
G:/Hlp/Glee/Test.cpp:302: undefined reference to `_imp____glewCreateShaderObjectARB'
G:/Hlp/Glee/Test.cpp:313: undefined reference to `_imp____glewCreateProgramObjectARB'
G:/Hlp/Glee/Test.cpp:315: undefined reference to `_imp____glewAttachObjectARB'
G:/Hlp/Glee/Test.cpp:316: undefined reference to `_imp____glewAttachObjectARB'
G:/Hlp/Glee/Test.cpp:319: undefined reference to `_imp____glewLinkProgramARB'
G:/Hlp/Glee/Test.cpp:324: undefined reference to `_imp____glewGetObjectParameterivARB'
 collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
23 errors, 0 warnings

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Hard broblems with linking GLEW library
« Reply #3 on: June 29, 2011, 03:51:26 pm »
Hm, have you read the link Ollydbg has given you?
I guess you've not, because this is pretty trivial error you're making...
In the FAQ, you can find other helpful info, please read all the items.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Kolcebruevsky

  • Single posting newcomer
  • *
  • Posts: 3
Re: Hard broblems with linking GLEW library
« Reply #4 on: June 29, 2011, 06:52:24 pm »
Thanks guys. I will trying solve it.

Offline seb_seb0

  • Almost regular
  • **
  • Posts: 166
Re: Hard broblems with linking GLEW library
« Reply #5 on: June 29, 2011, 10:04:40 pm »
I have had the same problem(s) lastly, since I work a lot with OpenGL these last months.
There are probably several troubles to address.
I assume you use GCC compiler (with library in "libxxxx.a") on Windows (because of gdi32...)

 1 - the order of the libraries is probably wrong. You should try this order:
            - glew
            - glut
            - glu32
            - opengl32
            - winmm
            - gdi32

  2 - naming convention of the lib: for GCC, if you use a library in ".lib", gcc has a lot of troubles to find it.
       This is also not a good idea to mix Visual Studio ".lib" and gcc ".a" libraries. Stick to gcc libraries. The best way is to avoid giving extension ".a" on the command line
       Your linker should look like that:
             glew32
             glut32
             glu32
             opengl32
             winmm
             gdi32

   3 - do no make the confusion between glu & glut. These are 2 different libraries. If you use GLUT, you will need GLU.

   4 - be careful when including opengl headers on Win32. windows.h must be included BEFORE opengl and all opengl libraries:
Code
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glew.h>
#include <gl/glut.h>

   5 - for glut at least, you have to make sure you are using the correct library (static linking versus dynamic linking)
        There is a compiler directive to define if you are using the static version (defined in gl/glut.h). You have also to make sure that the linker is using the correct version of the library.
        If you fail on this step, you will have a lot of "undefined reference : imp___xxxxx missing" kind of mistakes
        Here are the steps to link GLUT statically: (assuming FreeGlut, same apply for GLUT)
           - define in your project command line FREEGLUT_STATIC (menu project / build options, tab "compiler settings", tab "#define", add FREEGLUT_STATIC here)
           - make sure the glut libraries are correctly named (libfreeglut-static.a and libfreeglut.a) and use the correct one in the linker command line

    EDIT: for GLEW as well, you need to define #define GLEW_STATIC if you are using the static version of the lib. See here:
    http://forums.codeblocks.org/index.php?topic=7322.0;wap2

   Or use Glee (easy setup, same functionnality)
    
   6 - you can use the GLUT template in codeblocks. It works quite good with the original GLUT, and it can show you the right direction

   7 - see NeHe tutorials for step-by-step settings of OpenGL. A bit outdated, but perfect for beginners (I have started here also, 8 month ago)

As a side note, this is not Codeblocks related. If you are still stuck, try to search the web, and / or start with a simpler project
Good luck !

Sebastien
« Last Edit: June 29, 2011, 10:10:56 pm by seb_seb0 »