Author Topic: Linking GLUT32 with C::B  (Read 11198 times)

kostyabkg

  • Guest
Linking GLUT32 with C::B
« on: March 03, 2006, 04:39:53 pm »
Hi I am trying to compile test files from the redbook for OpenGL with C::B and Dev-C++ and I get the same error:
Quote
Project   : Console application
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\b1676805\Desktop\cb\test1\
--------------------------------------------------------------------------------
Switching to target: default
Linking console executable: C:\Documents and Settings\b1676805\Desktop\cb\test1\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

I put glut.h in the include directory, linked the library to libglut32, libopengl32 and libglu32 and this is what I get. I don't know where to look? This is probably some silly mistake of mine however I can't spot it. The test example in both of these IDEs compiles and runs just fine, but not the GLUT...

Thank you!
Kostya.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Linking GLUT32 with C::B
« Reply #1 on: March 03, 2006, 04:52:18 pm »
First of all a little side note:
Linking console executable: C:\Documents and Settings\b1676805\Desktop\cb\test1\console1.exe
Your errors are caused by the linker. So it's unlikely they are caused by missing header files. In this case the compiler would complain.

libglut32, libopengl32 and libglu32
Please make sure you are using the right order of the libraries you are linking with. This is importeant as they are based on each other. For OpenGL applications one would usually link (in this order) opengl32, glu32, glut32. I guess that's the cause of your problem.

Another side-note: Don't get me wrong, but this is a Code::Blocks forum. Your question is not really related to C::B, isnt' it?! :wink:

With regards, Morten.

Edit: I completely forgot: Are you aware that there is an OpenGL project template shipping with C::B?
« Last Edit: March 03, 2006, 04:59:30 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Linking GLUT32 with C::B
« Reply #2 on: March 03, 2006, 05:06:29 pm »
I put glut.h in the include directory, linked the library to libglut32, libopengl32 and libglu32 and this is what I get. I don't know where to look? This is probably some silly mistake of mine however I can't spot it. The test example in both of these IDEs compiles and runs just fine, but not the GLUT...

Did you put the in C::B the correct path(es) to your include and library files?

Best wishes,
Michael

kostyabkg

  • Guest
Re: Linking GLUT32 with C::B
« Reply #3 on: March 04, 2006, 04:27:32 pm »
Thank you for advice,
However, it seems like the order of linking libraries doesn't affect anything at all. Only when I include gl.h and glu.h files before glut.h it affects the thing. Then error looks like this:
Quote
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)

Yes, you are right, I shouldn't post this here, because you are very busy developing C::B and answering the forums posts and this really doesn't relate to C::B, therefore I posted this to OpenGL forum (which I should of done first) http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic&f=2&t=020079

My apologies, gentlemen...

Michael,
I didn't quite understand what you mean by saying
Quote
Did you put the in C::B the correct path(es) to your include and library files?

If you are going to answer, check first OpenGL link, maybe somebody answered there. I really respect your work guys and don't want to cause extra hassle.

Kostya.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Linking GLUT32 with C::B
« Reply #4 on: March 04, 2006, 05:12:48 pm »
Only when I include gl.h and glu.h files before glut.h it affects the thing. [...]
Mmmh. Sounds strange...?!
Well, here are my suggestions for today:
1.) What OpenGL libraries are you using? Are you sure that they are compatible with GCC? You could give a try to the OpenGL DevPack (search with google please since the download location I got it from seems to have changed).
2.) Do you mix incompatible headers, maybe? Thus you are using OpenGL headers from one package but linking with others?
3.) Did you give a try to the OpenGL template that ships with C::B? This really should work - it has been tested around thousand times or so... ;-)
4.) Could you please post a full compiler log? To enable full logging go into the compiler setup, choose the tab named "other" and set "Compiler logging" to "Full command line". Then post the full log again - this may help, too.
With regards, Morten.

Ps.: There is a NeHe OpenGL lessons thread somehwere else in the forum. You could try if these (simple) projects compile for you.

Edit: Typos... :-(
« Last Edit: March 04, 2006, 05:22:19 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

kostyabkg

  • Guest
Re: Linking GLUT32 with C::B
« Reply #5 on: March 04, 2006, 06:48:51 pm »
Happy days!!!
I downloaded glut devpack from Dev-C++ packs server and everything worked, then I copied glut.h and libglut32.a to the same directories of CodeBlocks, linked as it's done in Dev-C++ and everything worked.
I put .h and .a files in an archive, added readme and put it online in case somebody else would ever face the same problem. Here is the link:
http://www.geocities.com/kostyabkg/GLUT_mingw32.zip

Thank you for all the help!

P.S. The template that ships with C::B doesn't work with GLUT, but uses Win32 API, the same is true for NeHe lessons.
P.P.S. I discovered that C::B can download Dev-C++ packs as well! Good work, guys!

sethjackson

  • Guest
Re: Linking GLUT32 with C::B
« Reply #6 on: March 05, 2006, 02:35:55 am »
P.S. The template that ships with C::B doesn't work with GLUT, but uses Win32 API, the same is true for NeHe lessons.

Of course it won't work "out of the box" it was not intended too. :D I think it will work with some tinkering though.  :wink: