Issue using OpenGL

Hello, I am following a tutorial to learn the basics of OpenGL. My tutorial had a code snipit which included
1
2
#include <GL/glew.h>
#include <GL/freeglut.h> 
So I downloaded these libaries, and because I want all my files to be together in the same project, I copied all the header files from the include subdirectieres from these downloads into my project folder and added them to my project. However, when I run my program I am presented with a number of confusing compiler errors:
1
2
3
C:\Users\Owain\Documents\General_Programming\OpenGL\Learning\basics\freeglut_std.h|612|undefined reference to `_imp____glutInitWithExit@12'|
C:\Users\Owain\Documents\General_Programming\OpenGL\Learning\basics\freeglut_std.h|614|undefined reference to `_imp____glutCreateWindowWithExit@8'|
C:\Users\Owain\Documents\General_Programming\OpenGL\Learning\basics\freeglut_std.h|616|undefined reference to `_imp____glutCreateMenuWithExit@8'| 
I also tried downloading both the libaries to another location and linking them in my project but I still got the same errors.

Anyone who knows anyhing about OpenGL know whats going on?

P.S I am using Code::Blocks
Last edited on
It looks like you'll have to link against the OpenGL libraries, not just including the headers. I'm not familiar enough with OpenGL or Code::Blocks either to give you step by step instructions :(
First of all: Don't copy headers! That's just unneeded work. Instead, tell your compiler where to look for them - for example, in g++ this is done with the -Ithe_dir flag, (that's a big i, not a small L). If you're using an IDE you can probably tell it to tell the compiler where to look it up. In visual studio 2010, it's somewhere in the project settings - I forgot where exactly, but it's not hard to find.

Second: You forgot (or didn't know you had to) to link to glut. Again, in Visual Studio this can be done in the project settings (also remember to set the relevant search paths), in g++ you do it with -lthe_lib (where the_lib's filename is libthe_lib.a) - you can add a lib search path to g++ with the -Lpath option. Since you're on windows, the relevant libs will probably be called something like "gl32.lib" "glu32.lib" "glut32.lib" "glew32.lib". Note that all of those are different libraries and need to be linked separately to. Also note that you can link to .lib libs with MinGW by naming them as input files in the linking step, rather than specifying them with the -l option.

PS: Just saw the PS. The "Visual Studio" parts mostly apply to Code::Blocks as well. Since you're using Code::Blocks, you are probably using MinGW-g++ as your C++ compiler, so the g++ advices apply as well (if you ever feel the need to compile by hand or per makefile or similar).
Last edited on
Thankyou for responding! Well, I have done what you recommended, but I am still getting the error. I am using MinGW-g++ compiler, and here are my compiler settings:
1
2
3
4
5
6
-iC:\glew-1.7.0\include\GL
-iC:\freeglut-2.8.0\include\GL
-lC:\glew-1.7.0\lib\glew32s.lib
-lC:\glew-1.7.0\lib\glew32mxs.lib
-lC:\glew-1.7.0\lib\glew32mx.lib
-lC:\glew-1.7.0\lib\glew32.lib


Is this correct? Could there be any other reason why I am gettng these errors?
You are missing the [free]glut library there.
Okay, I downloaded the free libary and linked it, but I am still getting the same errors
MinGW should be using .a files (right?). If MinGW can use .lib, then you don't need the .lib in your make.
-lC:\glew-1.7.0\lib\glew32s
Last edited on
Topic archived. No new replies allowed.