PDA

View Full Version : Linking GLUT with CodeBlocks



kostyabkg
03-04-2006, 06:18 AM
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\test7\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: hello.c
Linking console executable: C:\Documents and Settings\kostya\My Documents\cpp\test7\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 to `glutInitWindowSize'
.objs\hello.o:hello.c:(.text+0x210): undefined reference to `glutInitWindowPosition'
.objs\hello.o:hello.c:(.text+0x22d): undefined reference to `glutDisplayFunc'
.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\test7\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: hello.c
Linking console executable: C:\Documents and Settings\kostya\My Documents\cpp\test7\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 (http://forums.codeblocks.org/index.php?topic=2529.0) ) 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!

songho
03-04-2006, 07:34 AM
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++?

kostyabkg
03-04-2006, 08:04 AM
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 :-(

Thank you.

kostyabkg
03-04-2006, 08:40 AM
Hey, I downloaded glut pack from devpacks.org server and everything worked, thank you for your advice!!!