# glut undefined?

**URL:** <https://community.khronos.org/t/glut-undefined/14242>\
**Category:** OpenGL: Basic Coding\
**Created:** [February 3, 2004, 3:56pm UTC](https://community.khronos.org/t/glut-undefined/14242 "2004-02-03T15:56:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![oGL\_nEwB](https://community.khronos.org/letter_avatar_proxy/v4/letter/o/e9bcb4/32.png) [@oGL\_nEwB](https://community.khronos.org/u/oGL_nEwB)\
**Post date:** [February 3, 2004, 3:56pm UTC](https://community.khronos.org/t/glut-undefined/14242/1 "2004-02-03T15:56:00Z")

</div>

lol now i have yet another error in devcpp  
after i have linked -lopengl32 -lglu32  
-lglut32. It says as a linker error this:

“c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x17):glcode.cpp: undefined reference to `__glutInitWithExit@12' c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x3b):glcode.cpp: undefined reference to`\_\_glutCreateWindowWithExit@8’  
c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x67):glcode.cpp: undefined reference to `\_\_glutCreateMenuWithExit@8’”

“c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x17):glcode.cpp: undefined reference to `__glutInitWithExit@12' c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x3b):glcode.cpp: undefined reference to`\_\_glutCreateWindowWithExit@8’  
c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x67):glcode.cpp: undefined reference to `\_\_glutCreateMenuWithExit@8’”

“c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x17):glcode.cpp: undefined reference to `__glutInitWithExit@12' c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x3b):glcode.cpp: undefined reference to`\_\_glutCreateWindowWithExit@8’  
c:\documents and settings\dylan snowden\desktop\my stuff\my c++\open gl\my opengl\glcode.o(.text+0x67):glcode.cpp: undefined reference to `\_\_glutCreateMenuWithExit@8’”

Geez i have one thing after the next…  
and i have all the files in the right folders.

---

<div class="post-metadata">

**Author:** ![chowe6685](https://community.khronos.org/letter_avatar_proxy/v4/letter/c/a6a055/32.png) [@chowe6685](https://community.khronos.org/u/chowe6685)\
**Post date:** [February 3, 2004, 4:50pm UTC](https://community.khronos.org/t/glut-undefined/14242/2 "2004-02-03T16:50:00Z")

</div>

#define GLUT\_DISABLE\_ATEXIT\_HACK

---

<div class="post-metadata">

**Author:** ![nexusone](https://community.khronos.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nexusone](https://community.khronos.org/u/nexusone)\
**Post date:** [February 4, 2004, 4:06am UTC](https://community.khronos.org/t/glut-undefined/14242/3 "2004-02-04T04:06:00Z")

</div>

Need to see your code in order to say what you are doing wrong.

[This message has been edited by nexusone (edited 02-04-2004).]

---

<div class="post-metadata">

**Author:** ![oGL\_nEwB](https://community.khronos.org/letter_avatar_proxy/v4/letter/o/e9bcb4/32.png) [@oGL\_nEwB](https://community.khronos.org/u/oGL_nEwB)\
**Post date:** [February 4, 2004, 11:02am UTC](https://community.khronos.org/t/glut-undefined/14242/4 "2004-02-04T11:02:00Z")

</div>

ok i have dled the nehe 1st tutorial… for glut based and i have tried to compile it in devcpp and those are the errors i get. i have dled also the glut libraries and the dlls and so on…

here is the code

> ```auto
> /*
> NeHe (nehe.gamedev.net) OpenGL tutorial series
> GLUT port.in 2001 by milix (milix_gr@hotmail.com)
> Most comments are from the original tutorials found in NeHe.
> For VC++ users, create a Win32 Console project and link 
> the program with glut32.lib, glu32.lib, opengl32.lib
> */
> 
> #include <windows.h> // Standard Header For MSWindows Applications
> #include <gl/glut.h> // The GL Utility Toolkit (GLUT) Header
> 
> // The Following Directive Fixes The Problem With Extra Console Window
> #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
> 
> // Global Variables
> bool g_gamemode; // GLUT GameMode ON/OFF
> bool g_fullscreen; // Fullscreen Mode ON/OFF (When g_gamemode Is OFF)
> 
> // Our GL Specific Initializations
> bool init(void)
> {
> glShadeModel(GL_SMOOTH); // Enable Smooth Shading
> glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
> glClearDepth(1.0f); // Depth Buffer Setup
> glEnable(GL_DEPTH_TEST); // Enables Depth Testing
> glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
> glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
> return true;
> }
> 
> // Our Rendering Is Done Here
> void render(void)   
> {
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
> glLoadIdentity(); // Reset The Current Modelview Matrix
> 
> // Swap The Buffers To Become Our Rendering Visible
> glutSwapBuffers ( );
> }
> 
> // Our Reshaping Handler (Required Even In Fullscreen-Only Modes)
> void reshape(int w, int h)
> {
> glViewport(0, 0, w, h);
> glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
> glLoadIdentity(); // Reset The Projection Matrix
> // Calculate The Aspect Ratio And Set The Clipping Volume
> if (h == 0) h = 1;
> gluPerspective(80, (float)w/(float)h, 1.0, 5000.0);
> glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
> glLoadIdentity(); // Reset The Modelview Matrix
> }
> 
> // Our Keyboard Handler (Normal Keys)
> void keyboard(unsigned char key, int x, int y)
> {
> switch (key) {
> case 27: // When Escape Is Pressed...
> exit(0); // Exit The Program
> break; // Ready For Next Case
> default: // Now Wrap It Up
> break;
> }
> }
> 
> // Our Keyboard Handler For Special Keys (Like Arrow Keys And Function Keys)
> void special_keys(int a_keys, int x, int y)
> {
> switch (a_keys) {
> case GLUT_KEY_F1:
> // We Can Switch Between Windowed Mode And Fullscreen Mode Only
> if (!g_gamemode) {
> g_fullscreen = !g_fullscreen; // Toggle g_fullscreen Flag
> if (g_fullscreen) glutFullScreen(); // We Went In Fullscreen Mode
> else glutReshapeWindow(500, 500); // We Went In Windowed Mode
> }
> break;
> default:
> break;
> }
> }
> 
> // Ask The User If He Wish To Enter GameMode Or Not
> void ask_gamemode()
> {
> int answer;
> // Use Windows MessageBox To Ask The User For Game Or Windowed Mode
> answer = MessageBox(NULL, "Do you want to enter game mode?", "Question",
> MB_ICONQUESTION | MB_YESNO);
> g_gamemode = (answer == IDYES);
> // If Not Game Mode Selected, Use Windowed Mode (User Can Change That With F1)
> g_fullscreen = false; 
> }
> 
> // Main Function For Bringing It All Together.
> int main(int argc, char** argv)
> {
> ask_gamemode(); // Ask For Fullscreen Mode
> glutInit(&argc, argv); // GLUT Initializtion
> glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Display Mode (Rgb And Double Buffered)
> if (g_gamemode) {
> glutGameModeString("640x480:16"); // Select The 640x480 In 16bpp Mode
> if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
> glutEnterGameMode(); // Enter Full Screen
> else g_gamemode = false; // Cannot Enter Game Mode, Switch To Windowed
> }
> if (!g_gamemode) {
> glutInitWindowSize(500, 500); // Window Size If We Start In Windowed Mode
> glutCreateWindow("NeHe's OpenGL Framework"); // Window Title 
> }
> init(); // Our Initialization
> glutDisplayFunc(render); // Register The Display Function
> glutReshapeFunc(reshape); // Register The Reshape Handler
> glutKeyboardFunc(keyboard); // Register The Keyboard Handler
> glutSpecialFunc(special_keys); // Register Special Keys Handler
> glutMainLoop(); // Go To GLUT Main Loop
> return 0;
> }
> 
> ```

well?  
o and this is with the newer devcpp

---

<div class="post-metadata">

**Author:** ![nexusone](https://community.khronos.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nexusone](https://community.khronos.org/u/nexusone)\
**Post date:** [February 4, 2004, 11:16am UTC](https://community.khronos.org/t/glut-undefined/14242/5 "2004-02-04T11:16:00Z")

</div>

How did you setup the project?  
As a windows application or console?  
Also did you select C or C++ option?

If you create is as a windows program, you may need to live this bit of code out on DEV-C++

#pragma comment(linker, “/subsystem:“windows” /entry:“mainCRTStartup””)

---

<div class="post-metadata">

**Author:** ![oGL\_nEwB](https://community.khronos.org/letter_avatar_proxy/v4/letter/o/e9bcb4/32.png) [@oGL\_nEwB](https://community.khronos.org/u/oGL_nEwB)\
**Post date:** [February 4, 2004, 12:08pm UTC](https://community.khronos.org/t/glut-undefined/14242/6 "2004-02-04T12:08:00Z")

</div>

nope it didnt work…  
now that im usin the new devcpp i have these errors

"

[Linker error] undefined reference to `\_\_glutInitWithExit@12’

[Linker error] undefined reference to `\_\_glutCreateWindowWithExit@8’

[Linker error] undefined reference to `\_\_glutCreateMenuWithExit@8’

[Linker error] undefined reference to `glShadeModel@4’

[Linker error] undefined reference to `glClearColor@16’

[Linker error] undefined reference to `glClearDepth@8’

[Linker error] undefined reference to `glEnable@4’

[Linker error] undefined reference to `glDepthFunc@4’

[Linker error] undefined reference to `glHint@8’

[Linker error] undefined reference to `glClear@4’

[Linker error] undefined reference to `glLoadIdentity@0’

[Linker error] undefined reference to `glutSwapBuffers@0’

[Linker error] undefined reference to `glViewport@16’

[Linker error] undefined reference to `glMatrixMode@4’

[Linker error] undefined reference to `glLoadIdentity@0’

[Linker error] undefined reference to `gluPerspective@32’

[Linker error] undefined reference to `glMatrixMode@4’

[Linker error] undefined reference to `glLoadIdentity@0’

[Linker error] undefined reference to `glutFullScreen@0’

[Linker error] undefined reference to `glutReshapeWindow@8’

[Linker error] undefined reference to `glutInitDisplayMode@4’

[Linker error] undefined reference to `glutGameModeString@4’

[Linker error] undefined reference to `glutGameModeGet@4’

[Linker error] undefined reference to `glutEnterGameMode@0’

[Linker error] undefined reference to `glutInitWindowSize@8’

[Linker error] undefined reference to `glutDisplayFunc@4’

[Linker error] undefined reference to `glutReshapeFunc@4’

[Linker error] undefined reference to `glutKeyboardFunc@4’

[Linker error] undefined reference to `glutSpecialFunc@4’

[Linker error] undefined reference to `glutMainLoop@0’ "

ok lol i think it deffinately has sumtin to do with headers or the dll’s but see in devcpp 5 i havnt seen one GL dll in the directories of devcpp except 2 for like c++

am i missin sumtin?

---

<div class="post-metadata">

**Author:** ![soft\_peach](https://community.khronos.org/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@soft\_peach](https://community.khronos.org/u/soft_peach)\
**Post date:** [February 4, 2004, 1:16pm UTC](https://community.khronos.org/t/glut-undefined/14242/7 "2004-02-04T13:16:00Z")

</div>

[QUOTE]Originally posted by oGL\_nEwB:  
now that im usin the new devcpp i have these errors

"

[Linker error] undefined reference to `\_\_glutInitWithExit@12’

[Linker error] undefined reference to `\_\_glutCreateWindowWithExit@8’

* * *

try adding a

#define GLUT\_DISABLE\_ATEXIT\_HACK

just before your include to gl/glut.h

I had the same problem as you with devcpp, and this #define solved mine.

[This message has been edited by soft peach (edited 02-04-2004).]

---

<div class="post-metadata">

**Author:** ![oGL\_nEwB](https://community.khronos.org/letter_avatar_proxy/v4/letter/o/e9bcb4/32.png) [@oGL\_nEwB](https://community.khronos.org/u/oGL_nEwB)\
**Post date:** [February 5, 2004, 5:19am UTC](https://community.khronos.org/t/glut-undefined/14242/8 "2004-02-05T05:19:00Z")

</div>

lol  
ok that solved the exit problem …  
lol but now i have these errors. some of the glut functions arent working like glutCreateWindow and some of the gl’s arent working… here are the errors…  
(i am also using the nehe glut based code to compile and it still doesnt work)

[Linker error] undefined reference to `glShadeModel@4’

[Linker error] undefined reference to `glClearColor@16’

[Linker error] undefined reference to `glClearDepth@8’

[Linker error] undefined reference to `glEnable@4’

[Linker error] undefined reference to `glDepthFunc@4’

[Linker error] undefined reference to `glHint@8’

[Linker error] undefined reference to `glClear@4’

[Linker error] undefined reference to `glLoadIdentity@0’

[Linker error] undefined reference to `glutSwapBuffers@0’

[Linker error] undefined reference to `glViewport@16’

[Linker error] undefined reference to `glMatrixMode@4’

[Linker error] undefined reference to `glLoadIdentity@0’

[Linker error] undefined reference to `gluPerspective@32’

[Linker error] undefined reference to `glMatrixMode@4’

[Linker error] undefined reference to `glLoadIdentity@0’

[Linker error] undefined reference to `glutFullScreen@0’

[Linker error] undefined reference to `glutReshapeWindow@8’

[Linker error] undefined reference to `glutInit@8’

[Linker error] undefined reference to `glutInitDisplayMode@4’

[Linker error] undefined reference to `glutGameModeString@4’

[Linker error] undefined reference to `glutGameModeGet@4’

[Linker error] undefined reference to `glutEnterGameMode@0’

[Linker error] undefined reference to `glutInitWindowSize@8’

[Linker error] undefined reference to `glutCreateWindow@4’

[Linker error] undefined reference to `glutDisplayFunc@4’

[Linker error] undefined reference to `glutReshapeFunc@4’

[Linker error] undefined reference to `glutKeyboardFunc@4’

[Linker error] undefined reference to `glutSpecialFunc@4’

[Linker error] undefined reference to `glutMainLoop@0’

almost as if it isnt reading the glut and gl library files… but like i said before i have not seen one dll for gl glut or glu. does devcpp 5 already link them or somethin?

---

<div class="post-metadata">

**Author:** ![theUnknowing](https://community.khronos.org/letter_avatar_proxy/v4/letter/t/65b543/32.png) [@theUnknowing](https://community.khronos.org/u/theUnknowing)\
**Post date:** [February 5, 2004, 5:30am UTC](https://community.khronos.org/t/glut-undefined/14242/9 "2004-02-05T05:30:00Z")

</div>

Well, it’s probably not the same problem, but the first thing I do when I get a slew of similar type errors, I check to make sure my Library files are properly set up. Using Visual C++, I check under Project-\>Settings, and hit the Link tab. For almost any file in my ‘Include’ headers, I make sure I have the right ‘.lib’ file listed.

For example, for #include \<gl/gl.h\> I make sure I have ‘opengl32.lib’ referenced. For GLUT, it needs ‘glut32.lib’, etc.

You’ve probably checked all this out already, but it never hurts to double-check.

---

<div class="post-metadata">

**Author:** ![theUnknowing](https://community.khronos.org/letter_avatar_proxy/v4/letter/t/65b543/32.png) [@theUnknowing](https://community.khronos.org/u/theUnknowing)\
**Post date:** [February 5, 2004, 5:39am UTC](https://community.khronos.org/t/glut-undefined/14242/10 "2004-02-05T05:39:00Z")

</div>

Or there’s another possibility. You made reference to not being able to find .dll files… installing OpenGL provides you with the .dll files you need, but it doesn’t necessarily put them anywhere where they’d be easy to get at. You’d have to setup your development software to look in the directory where the files are kept. Or (and this is what I do to prevent any doubt), I simply take the important dll files (glut32.dll, opengl32.dll, etc), and copy them into my Windows/System folder. No muss, no fuss.

If you installed OpenGL correctly, the .dll’s ARE there… somewhere. ![](http://www.opengl.org/discussion_boards/ubb/smile.gif)

---

<div class="post-metadata">

**Author:** ![nexusone](https://community.khronos.org/letter_avatar_proxy/v4/letter/n/f0a364/32.png) [@nexusone](https://community.khronos.org/u/nexusone)\
**Post date:** [February 5, 2004, 7:55am UTC](https://community.khronos.org/t/glut-undefined/14242/11 "2004-02-05T07:55:00Z")

</div>

Did you put the -lopengl32 -lglu32 -lglut32 in the correct location in the linker options?

Also are you using the openGL librarys supplied with DEV-C++?

---

<div class="post-metadata">

**Author:** ![Kitsune64](https://community.khronos.org/user_avatar/community.khronos.org/kitsune64/32/6847_2.png) [@Kitsune64](https://community.khronos.org/u/Kitsune64)\
**Post date:** [March 6, 2021, 2:41pm UTC](https://community.khronos.org/t/glut-undefined/14242/12 "2021-03-06T14:41:25Z")

</div>

`#define GLUT_DISABLE_ATEXIT_HACK`

That solved the trouble in Codeblocks and OpenGL Glut project for me, I had add also #include \<windows.h\> in First line of the code.

In link libraries I have:  
glut32  
opengl32  
glu32  
winmm  
gdi32
