Linking problem in Code::Blocks with OpenGL/GLUT

Hi, folks, I installed a new IDE called Code::Blocks after using DevC++ quite a while and now I´ve almost completely moved to use Code::Blocks. I love it. However, linking OpenGL & GLUT turns out to be very frustrating - things just don´t work. I did some research, tried this one out:
http://www.allegro.cc/forums/thread/596253

And then this:
http://www.levelbylevel.com/tutorials/opengl-c-and-glut-using-codeblocks-and-mingw-updated/

And then this:
http://hubpages.com/hub/How-to-set-up-you-CodeBlocks-for-openGL-lasthopez

And of course, it doesn´t work. Nice. Friggin' beautiful. Could somebody help me out here? Using OpenGL and GLUT would be a very welcome thing for me, I need it.

Oh, and if I have to download some files (pretty surely I have to), please send me download links too, because not all versions of the specific files work together (latest ones, please).
Can you be more precise about the problems you are having? Are you getting some compiler/runtime errors? If so, what are they?
Oh, my bad, here are some of my errors:

F:\Programs\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\GL\glut.h|455|undefined reference to `_imp____glutInitWithExit@12'|
F:\Programs\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\GL\glut.h|472|undefined reference to `_imp____glutCreateWindowWithExit@8'|
F:\Programs\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\GL\glut.h|518|undefined reference to `_imp____glutCreateMenuWithExit@8'|
F:\Programs\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\GL\glut.h|472|undefined reference to `_imp____glutCreateWindowWithExit@8'|
F:\Programs\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\GL\glut.h|518|undefined reference to `_imp____glutCreateMenuWithExit@8'|
F:\Programs\Dev-Cpp\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\include\GL\glut.h|472|undefined reference to `_imp____glutCreateWindowWithExit@8'|


In total, 24 errors, 18 warnings

I included these:
gl.h
glu.h
glut.h

And these are my libraries I linked (in order I put them in, as in relative path):
libglut32.a
libglu32.a
libopengl32.a
libgdi32.a
libwinmm.a

And these I have in System32 folder (I´m using Windows Vista):
glu32.dll
glut32.dll
opengl32.dll

Enough information?
Do you definitely have the most recent version of Code::Blocks, as those errors appear to be in the OpenGL headers themselves. Coincidentally, since you're on Windows, you could also try Visual C++ Express, just to see if the problem is limited to the headers with Code::Blocks. Did you not get this issue in DevC++?
Although I linked files bit differently in DevC++, there were no errors or warnings. I use Code::Blocks, because I want to create as portable code as possible (OpenGL/GLUT is used for the same reason) and to my knowledge, Visual C++ Express or Visual Studio are mostly Microsoft specific - or, are they? Oh, and Code::Blocks is up-to-date, DevC++ isn´t and I have the recent version of Code::Blocks right now.

Any help?
Wasn't "libglut32.a" depricated or something like that? Which tutorial are you working off of OP?

By the way, the IDE itself Dev-C++ isn't installable cross-platform (because it's written in Pascal?). Actual compatiblility or your applications would be determined by your compiler, which I see in mingw and the libs that you use.

If you plan on distributing for Linux, it seems that a lot of people just drop the source code in a tar ball anyway and that precompiling it leads to more and more issues.
Last edited on
Visual C++ Express or Visual Studio are mostly Microsoft specific

Well if you are careful, code written in Visual Studio can still be portable, though there are of course vendor specific features as well. I only was suggesting this to see if you avoided the problem by using the OpenGL header file from a different vendor. I wasn't suggesting you need swap permanently :P

Code::Blocks is up-to-date, DevC++ isn´t and I have the recent version of Code::Blocks right now

Quite right too. I would never suggest someone used Dev C++ over Code::Blocks.

Do you still get these errors when you comment out most of your source code, just leaving a basic main function and the three OpenGL headers?
Add the libraries in the right order.
You appeared to have added them backwards.

Your order
libglut32.a
libglu32.a
libopengl32.a
libgdi32.a
libwinmm.a

The reference you posted says this way http://www.levelbylevel.com/tutorials/opengl-c-and-glut-using-codeblocks-and-mingw-updated/
libopengl32.a
libglu32.a
libglut32.a
libgdi32.a
libwinmm.a

Edit: You two sets of directions differ in the correct order of the Library; I suggest trying this way since you current way failed to work.

The order CB Wizard does is
glut32
opengl32
glu32
winmm
gdi32

Tim S.

Last edited on
It seems to like that GLUT is the only one that doesn´t work. When I include these...

1
2
#include <GL/gl.h>
#include <GL/glu.h> 


...compiler doesn´t warn of display any erros, but after I put this after those...

 
#include <GL/glut.h> 


...it doesn´t work.

And unfortunately, changing the order as you suggested stahta01 doesn´t work either.
So, has anyone even managed to succesfully link OpenGL and GLUT files in Code::Blocks?
I can tell you that you probably don't need it. I mentioned that it might be depricated because looking back at my past projects I saw that I had it commented out with a note saying "Not Needed". These were all functioning mini games by the way.
Well how can I set up a window for my project then (and get keyboard actions etc.)?
I can't help with GLUT, sorry. But I could suggest alternate libraries for window management. You could use either SDL (http://www.libsdl.org/) or SFML (http://sfml-dev.org/) to set up the window. Both have integrated graphics capabilities, but both also support use of OpenGL directly. I suggest SFML :)
+1 Xander314 for SFML, you can learn how to create a rendering context in SFML in a weekends time. It also works VERY well with OpenGL and has a really straight forward well organized tutorial on the website.
Topic archived. No new replies allowed.