Linker errors using Dev-C++, need help


I have started coding using OpenGL yesterday using Dev-C++ compiler( I think this compiler comes with all the GL librairies and DLL but I am not sure.

So to start with I downloaded GLUT (headers n DLL) form this link:

Then I tried to compiled this source which will just creat and display a window:


#include <windows.h>
#include <glut.h>

void init(void)
glClearColor(1.0, 1.0, 1.0, 0.0) ;
glShadeModel(GL_FLAT) ;

void display(void)
glutSwapBuffers() ;

int main(int argc, char** argv)
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ;
glutInitWindowSize (400, 100) ;
glutInitWindowPosition (100, 100) ;
glutCreateWindow (“First Chapter - Opening an OpenGL Window”) ;

init() ;
glutDisplayFunc (display) ;

glutMainLoop () ;

return 0 ;


And here are the linker errors I get:

c:\mes documents\untitled1.o: In function display(void)': //c/mes documents/untitled1.cpp:16: undefined reference toglutSwapBuffers@0’
c:\mes documents\untitled1.o: In function main': //c/mes documents/untitled1.cpp:35: undefined reference toglutInit@8’
//c/mes documents/untitled1.cpp:38: undefined reference to glutInitDisplayMode@4' //c/mes documents/untitled1.cpp:43: undefined reference toglutInitWindowSize@8’
//c/mes documents/untitled1.cpp:47: undefined reference to glutInitWindowPosition@8' //c/mes documents/untitled1.cpp:52: undefined reference toglutCreateWindow@4’
//c/mes documents/untitled1.cpp:59: undefined reference to glutDisplayFunc@4' //c/mes documents/untitled1.cpp:65: undefined reference toglutMainLoop@0’

Can you help me ?

Sorry for the bad use of the UBB code

I think what you need to do is link to the glut32.lib file… i know how to do it in visual studio but not the program you are using … however there IS a #pragma call for it but i don’t know it

hope something i said helped!

Looks like you’re not linking with glut. What does your link command line look like? Somewhere in it, it should have something like this:

-L<gl directory> -lopengl32 -lglu32 -lglut32

#pragma comment(lib, “glut32.lib”)

just make sure that glut32.lib is in your library directory

I don’t understand this #pragma notion but I put this line:
#pragma comment(lib, “glut32.lib”)
at diferent part of my source (before window.h, after window.h, then after glut.h) but the result is the same.

Then I modified the command line where there was only this written:
I have added this to it:
-lglu32 -lglut32
But it gaves me the same linker errors.

I have the glut32.lib file in my include directory but apparently it cannot ne linked.

Wait a minute! Doesn’t Dev-C++ use MinGW (which is in fact GCC)?? Then you need a file called libglut32.a, not glut32.lib. It should be included in the MinGW package, if not, check this link:

(a bit down on the page)

Your problem is that your not linking with glut library. To do this in Dev you go to the Project menu and Project options. Where it says “further object files or linker options” type “-lglut32” (without the quotes).

can you help me on how to use GLUT with dev-C++.
Should I download normal GLUT librairies and header frm openGL site:

Or do i need GLUT for mingw32 which can be found here:
And downloaded form this link:

Because I have tried both of them and I still cannot compile the source quoted above.

Any help on installing and using GLUT with Dev-C++ wud be greatly appreciated. And help me to compile my first gl program.

I tried what suggested shrlock and it gave me this error linking error:
g++: installation problem, cannot exec `ld’: No such file or directory

Thx for reading, hope u can help.


To fix the problem change <glut.h> to <gl/glut.h>.

The library file should be named ‘libglut32.a’ (this is for MinGW/GCC, for e.g. MSVC it’s ‘glut32.lib’), and it should be located in your compilers ‘lib’ directory.

For MinGW (which is used by Dev-C++, I believe), you should be able to compile when you add ‘-lglut32’ to your linker options line.

Thank you all for helping me out.

I finally managed to compile my code. I created a “temp” folder in the “Dev-C++” directory where I stored every librairies and header found on internet. I added this directory to be search for include files by going to “Compiler options”.

I copied/pasted all the files I found in the GLUT package downloaded from this site:

Here is my code with all the comments I added so that I know what it does. This code simply displays a blank windows, I am learning openGL from this site:

#include<windows.h> //needs to be include before OpenGL header files
#include <glut.h>
/In order to use OpenGL and GLUT, GL Utility Toolkit; it contains references to the header files opengl.h and glu.h/

void display(void)
// must be called prior to any drawing as it clears the background
//it accepts one argument that specifies the desired buffer to be cleared
//it swaps the back buffer with the front buffer, as when a window is double buffered
//If a window had only a single buffer the call glFlash would be used instead.

void init(void)
glClearColor(1.0, 1.0, 1.0, 0.0) ; //sets the initial clearing colour
//fourth value (0.0) is the one called alpha value and is normally used for blending

glShadeModel(GL_FLAT) ; //sets the shading model
//The shading model can be either GL_SMOOTH or GL_FLAT
//GL_FLAT: only one colour per polygon is used
//GL_SMOOTH: the colour of a polygon is interpolated among the colours of its vertices

//main fonction
int main (int argc, char** argv)
glutInit(&argc, argv); //GLUT is initialised

//display mode of the window is initialised
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
/This function accepts quite a few arguments as the display mode of a window can be double or single buffered, RGB or indexed colour table, with or without a depth buffer etc/

//sets the size of the window
/accepts 2 arguments which are its width and height in pixels/

//sets the window’s initial position
/accepts two arguments which are the horizontal and vertical distance (in pixels) from the upper left corner of the monitor/

//creates the actual window
glutCreateWindow(“First Chapter - Opening an OpenGL Window”);
/accepts a string which will be used as the window’s name as its argument/

//responsible for any initialisation needed prior to the window construction and/or visualisation

//event callback function
glutDisplayFunc (display);
/callback functions are special functions that are registered in order to do some specific operations. This fonction refresh the content of the window. Display is the function registered as the display callback by calling the function

glutMainLoop ();

return 0;

I added this line “-lopengl32 -lglut32” in the “project options”.

Hope this can help anyone starting in OpenGL using GLUT and dev-c++.

Dude you don’t know how much i wanna thank you! i have been working on fixing all the F****** error messages i had the same problem as u!!! for 5 hours i couldn’t fix it!!! and finally, finally i compile something thank you so much man.

for some reason glut isnt working for me. Everytime i use it, when i compile my code, it says “Required .dll GLUT32.DLL not found”. Can anyone help me

for some reason glut isnt working for me. Everytime i use it, when i compile my code, it says “Required .dll GLUT32.DLL not found”. Can anyone help me

Originally posted by userdefined:
for some reason glut isnt working for me. Everytime i use it, when i compile my code, it says “Required .dll GLUT32.DLL not found”. Can anyone help me

Make sure you have the required dll in your windows\system folder.

thanks alot for your help. finally i can compile my code.