Linking GLUT with CodeBlocks

Hello,
I am trying to compile hello.c example from the redbook. I am using CodeBlocks and/or Dev-C++ and get the same error:

Project : Console application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\kostya\My Documents\cpp est7\

Switching to target: default
Compiling: hello.c
Linking console executable: C:\Documents and Settings\kostya\My Documents\cpp est7\console1.exe
.objs\hello.o:hello.c:(.text+0x1c): undefined reference to __glutInitWithExit' .objs\hello.o:hello.c:(.text+0x37): undefined reference to__glutCreateWindowWithExit’
.objs\hello.o:hello.c:(.text+0x52): undefined reference to __glutCreateMenuWithExit' .objs\hello.o:hello.c:(.text+0x66): undefined reference to_imp__glClear’
.objs\hello.o:hello.c:(.text+0x87): undefined reference to _imp__glColor3f' .objs\hello.o:hello.c:(.text+0x95): undefined reference to_imp__glBegin’
.objs\hello.o:hello.c:(.text+0xb6): undefined reference to _imp__glVertex3f' .objs\hello.o:hello.c:(.text+0xd7): undefined reference to_imp__glVertex3f’
.objs\hello.o:hello.c:(.text+0xf8): undefined reference to _imp__glVertex3f' .objs\hello.o:hello.c:(.text+0x119): undefined reference to_imp__glVertex3f’
.objs\hello.o:hello.c:(.text+0x120): undefined reference to _imp__glEnd' .objs\hello.o:hello.c:(.text+0x127): undefined reference to_imp__glFlush’
.objs\hello.o:hello.c:(.text+0x159): undefined reference to _imp__glClearColor' .objs\hello.o:hello.c:(.text+0x167): undefined reference to_imp__glMatrixMode’
.objs\hello.o:hello.c:(.text+0x16e): undefined reference to _imp__glLoadIdentity' .objs\hello.o:hello.c:(.text+0x19c): undefined reference to_imp__glOrtho’
.objs\hello.o:hello.c:(.text+0x1e8): undefined reference to glutInitDisplayMode' .objs\hello.o:hello.c:(.text+0x1fc): undefined reference toglutInitWindowSize’
.objs\hello.o:hello.c:(.text+0x210): undefined reference to glutInitWindowPosition' .objs\hello.o:hello.c:(.text+0x22d): undefined reference toglutDisplayFunc’
.objs\hello.o:hello.c:(.text+0x232): undefined reference to `glutMainLoop’
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

When I add

Project : Console application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\kostya\My Documents\cpp est7\

Switching to target: default
Compiling: hello.c
Linking console executable: C:\Documents and Settings\kostya\My Documents\cpp est7\console1.exe
.objs\hello.o:hello.c:(.text+0x1c): undefined reference to __glutInitWithExit@12' .objs\hello.o:hello.c:(.text+0x3c): undefined reference to__glutCreateWindowWithExit@8’
.objs\hello.o:hello.c:(.text+0x5c): undefined reference to `__glutCreateMenuWithExit@8’
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

It’s obvious that it’s the linker error.
I linked files as suggested ( C::B forum ) in the following order
opengl32, glu32, glut32, however it doesn’t effect anything at all. Help me, please, what am I doing wrong here?
Thank you!

Try to link glut lib first and include glut.h first:
-lglut32 -lopengl32 -lglu32

If you are using glut, glut will include gl.h and glu.h automatically. Because glut requires both headers, you do not need to explicitly include them in your code, only glut.h is enough.

Have you compiled and run the OpenGL/glut template program, which is included in Dev-C++?

There is no OpenGL/glut template program in Dev-C++. The one there for OpenGL uses Win32 API and doesn’t use GLUT at all.
I followed your advice, no luck :frowning:

Thank you.

Hey, I downloaded glut pack from devpacks.org server and everything worked, thank you for your advice!!!