Author Topic: Code Blocks Error Message with GLUT  (Read 48737 times)

studiox

  • Guest
Code Blocks Error Message with GLUT
« on: October 02, 2005, 04:21:13 am »
Hi

I am very new to all this, so please bare with me.  We use Visual Studio.NET at school for C++ programs linked with all the openGL lib and stuff, I need an editor for home so i can compile my work, that is why i got Code Blocks and i need to configure it.  I am getting this error message when i compile my prog:

C:/Program Files/CodeBlocks/include/GL/glut.h:50: error: redeclaration of C++ built-in type `short'

I have no clue what this means, any ideas.  Also, how do i link/configure with Code Blocks the openGL lib?

thanks!

studiox

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #1 on: October 02, 2005, 04:57:13 am »
Also, 1 more thing i just realized.  When i build, i get this message

Linking executable: C:\_Courses\CPS511 - Graphics\Lab3\Lab3.exe
.objs\lab.o:lab.cpp:(.text+0x77d): undefined reference to `_imp__gluOrtho2D'
.objs\lab.o:lab.cpp:(.text+0x7be): undefined reference to `glutInit'
.objs\lab.o:lab.cpp:(.text+0x7ca): undefined reference to `glutInitDisplayMode'
.objs\lab.o:lab.cpp:(.text+0x7de): undefined reference to `glutInitWindowSize'
.objs\lab.o:lab.cpp:(.text+0x7f2): undefined reference to `glutInitWindowPosition'
.objs\lab.o:lab.cpp:(.text+0x7fe): undefined reference to `glutCreateWindow'
.objs\lab.o:lab.cpp:(.text+0x80a): undefined reference to `glutDisplayFunc'
.objs\lab.o:lab.cpp:(.text+0x816): undefined reference to `glutMouseFunc'
.objs\lab.o:lab.cpp:(.text+0x820): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
 

studiox

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #2 on: October 02, 2005, 05:55:13 am »
okay, figure it out, it was linking lib issues with glu, glut & openGL.

Now i have one new problem.  It builds fine, but when i "compile & run" i get an error pop up box saying
"The dynamic link library glut32.dll could not be found in C:\................................."very long file path which starts with where my cpp file sits and adds all these others weird C:\ paths to it.  What is wrong now?

pls help, i really wanna try this editor!

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Code Blocks Error Message with GLUT
« Reply #3 on: October 02, 2005, 10:23:58 am »
Unfortunately, glut support in MinGW is not complete. But if you search a bit, you can find it online.
Take a look here.
Be patient!
This bug will be fixed soon...

himaja

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #4 on: October 04, 2005, 07:34:42 pm »

Hi,

I am having the same problem with linking with GLUT, could you tell me how you fixed this error??

"C:/Program Files/CodeBlocks/include/GL/glut.h:50: error: redeclaration of C++ built-in type `short'"

Thanks,
Himaja.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Code Blocks Error Message with GLUT
« Reply #5 on: October 04, 2005, 08:00:39 pm »
have you tried using the VCToolkit compiler instead of MinGW? (warning: Needs previous installation of the Windows SDK, too!)

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Code Blocks Error Message with GLUT
« Reply #6 on: October 04, 2005, 11:13:45 pm »
"The dynamic link library glut32.dll could not be found in C:\................................."very long file path which starts with where my cpp file sits and adds all these others weird C:\ paths to it.  What is wrong now?
That means you have to either copy the dll into the same directory where your program is (happens to be your project folder), or anywhere in your  PATH so the system can find it (most people use C:\windows or C:\windows\system32 for that matter).


"C:/Program Files/CodeBlocks/include/GL/glut.h:50: error: redeclaration of C++ built-in type `short'"
I don't get that kind of error, but I don't use the glut.h from MinGW. You can get everything related to GLUT from Nate Robin's site: http://www.xmission.com/~nate/glut.html (header, libraries, sources, everything).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Code Blocks Error Message with GLUT
« Reply #7 on: October 04, 2005, 11:17:24 pm »
Do you think we should contact the site author so he can testdrive codeblocks? :D

Hey, maybe we could make a codeblocks workspace for the glut! :)

studiox

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #8 on: October 05, 2005, 01:25:53 am »

Hi,

I am having the same problem with linking with GLUT, could you tell me how you fixed this error??

"C:/Program Files/CodeBlocks/include/GL/glut.h:50: error: redeclaration of C++ built-in type `short'"

Thanks,
Himaja.


To fix that error i had to put all the right files in all the right directories.
1)glut.h, gl.h and glu.h must be the codeblocks/include/GL directory
2)glu32.lib, glut32.lib and opengl32.lib must be in the codeblocks/lib directory
3)glu32.dll, glut.dll and opengl32.dll must be in the WINNT/ServicePackFiles/i386 directory

now after that is done, you have to set the path to those files in the codeblocks editor.  Open the codeblocks editor and open your file/project.
1)click "Project -> Build Options", click the "Linker" tab
2)In the Link Libraries box, add the path to all the *.lib & *.dll files listed above, so there will be 6 paths you will add
3)In the other linker options, add this code, exactly as it is below:
-lglut32
-lopengl32
-lglu32

....then click OK...

4)click "Compiler -> Compiler options", click "Linker" tab
6)add the path to the 3 *.dll files
7)add this again to the "other linker options box"
-lglut32
-lopengl32
-lglu32


that should do it

studiox

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #9 on: October 05, 2005, 01:29:04 am »
"The dynamic link library glut32.dll could not be found in C:\................................."very long file path which starts with where my cpp file sits and adds all these others weird C:\ paths to it.  What is wrong now?
That means you have to either copy the dll into the same directory where your program is (happens to be your project folder), or anywhere in your  PATH so the system can find it (most people use C:\windows or C:\windows\system32 for that matter).

I have copied the DLL to the same directory.  Now when i compile and run, i don't but that error anymore, but now it seems to crash.  I the the message, my application has generated errors and will be closed by windows, an error report is being created.  Whats the deal with that now?

sethjackson

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #10 on: October 05, 2005, 02:14:01 am »
Quote
I have copied the DLL to the same directory.  Now when i compile and run, i don't but that error anymore, but now it seems to crash.  I the the message, my application has generated errors and will be closed by windows, an error report is being created.  Whats the deal with that now?

Usually when that happens your code segfaults or something of that nature. Mind posting the code?

studiox

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #11 on: October 05, 2005, 03:41:56 am »
sure, this is the code:

#define BLACK 0
#include <GL/glut.h>
#include <stdio.h>


void draw_pixel(int ix, int iy, int value)
{
  glBegin(GL_POINTS);
    glVertex2i( ix, iy);
  glEnd();
}

void bres(int x1,int y1,int x2,int y2)
{
  int dx, dy, i, e;
  int incx, incy, inc1, inc2;
  int x,y;

  dx = x2 - x1;
  dy = y2 - y1;

  if(dx < 0) dx = -dx;
  if(dy < 0) dy = -dy;
  incx = 1;
  if(x2 < x1) incx = -1;
  incy = 1;
  if(y2 < y1) incy = -1;
  x=x1;
  y=y1;

  if(dx > dy)
    {
      draw_pixel(x,y, BLACK);
      e = 2*dy - dx;
      inc1 = 2*( dy -dx);
      inc2 = 2*dy;
      for(i = 0; i < dx; i++)
      {
         if(e >= 0)
         {
            y += incy;
            e += inc1;
         }
         else e += inc2;
         x += incx;
         draw_pixel(x,y, BLACK);
      }
   }
   else
   {
      draw_pixel(x,y, BLACK);
      e = 2*dx - dy;
      inc1 = 2*( dx - dy);
      inc2 = 2*dx;
      for(i = 0; i < dy; i++)
      {
        if(e >= 0)
        {
           x += incx;
           e += inc1;
        }
        else e += inc2;
        y += incy;
        draw_pixel(x,y, BLACK);
    }
  }
 }

void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    bres(200, 200, 100, 50); //EDGE 1
   bres(100, 50, 20, 20); //EDGE 2
   bres(20, 20, 80, 50); //EDGE 3
   bres(80, 50, 30, 30); //EDGE 4
   bres(30,30,200,200);  //EDGE 5
    glFlush();
}

int inPolygon(int x, int y, int px1, int py1, int px2, int py2, int crossings){
  if(((px1 < x && px2 > x)||(px1 > x && px2 < x)) && py1 > y && py2 > y){
    int cross = crossings + 1;
    return cross;
  }
  else if(((px1 < x && px2 > x)||(px1 > x && px2 < x)) && ((py1 < y && py2 > y) ||(py1 > y && py2 < y) )){
    int ypoint = py1 + ((py2-py1)/(px2-px1)) * (x-px1);
   if(ypoint > y){
      int cross = crossings + 1;
      return cross;
   }
  }
  else return crossings;
}

void mouse(int btn, int state, int x, int y)
{

/* mouse callback, checks if point is in polygon */
   if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN){
      y=500-y;

      int crossings = 0;
      crossings = inPolygon(x,y,200,200,100,50,crossings);
      crossings = inPolygon(x,y,100,50,20,20,crossings);
      crossings = inPolygon(x,y,20,20,80,50,crossings);
      crossings = inPolygon(x,y,80,50,30,30,crossings);
      crossings = inPolygon(x,y,30,30,200,200,crossings);

      if(crossings % 2 !=0){
         bres(x-1.5,y+1.5,x+1.5,y+1.5);
         bres(x+1.5,y+1.5,x+1.5,y-1.5);
         bres(x+1.5,y-1.5,x-1.5,y-1.5);
         bres(x-1.5,y-1.5,x-1.5,y+1.5);
      }
   }
}

void myinit()
{
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glColor3f(1.0, 0.0, 0.0);
    glPointSize(1.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 499.0, 0.0, 499.0);
}

int main(int argc, char** argv)
{

/* standard GLUT initialization */

    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(500,500); /* 500x500 pixel window */
    glutInitWindowPosition(0,0); /* place window top left on display */
    glutCreateWindow("Bresenham's Algorithm"); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */

   glutMouseFunc(mouse);

    myinit(); /* set attributes */

    glutMainLoop(); /* enter event loop */
}

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Code Blocks Error Message with GLUT
« Reply #12 on: October 05, 2005, 04:23:11 pm »
Do you think we should contact the site author so he can testdrive codeblocks? :D
Hey, maybe we could make a codeblocks workspace for the glut! :)

Generally a good idea, but unluckily GLUT is quite old (and somehow deprecated). As far as I know, Mark Kilgard gave up on it around 1998, and Nate Robins' version is some 3-4 years old, too (or so I believe).

Many OpenGL programmers will tell you "don't use GLUT, use freeglut" these days because of that (and because freeglut has a nicer license).

Unluckily, to run all those stone-age "how to draw a textured cube with OpenGL 1.1" tutorials that are on the web, you really need GLUT. Although the name "freeglut" suggests that it drops in as a more or less seemless replacement, reality is nothing like that (it was 2 years ago, maybe it is now...).

Speaking of GLUT alternatives, GLFW is a quite cool product (not only a OpenGL toolkit, but includes many things like keyboard and joystick handling, as well as threading/messaging). Personally, I recommend this as the toolkit of choice, as it is really easy to use, small, zlib-licensed, and it includes everything you probably need.
Strangely, nobody seems to really use GLFW for some reason, which is a shame (I know of no serious project using it).

It might be worthwile to contact Marcus Geelnard ("the GLFW guy"), though. It should not be too much pain to build it with Code::Blocks (I tried with Dev-CPP a year and a day ago, compiled out of the box) and make a GLFW application template, what do you think?



I am having the same problem [...] could you tell me how...

To fix that error i had to put all the right files in all the right directories.
1)glut.h, gl.h and glu.h must be the codeblocks/include/GL directory
2)glu32.lib, glut32.lib and opengl32.lib must be in the codeblocks/lib directory
3)glu32.dll, glut.dll and opengl32.dll must be in the WINNT/ServicePackFiles/i386 directory
1) and 2) are correct, but 3) is (at least in a normal setup) not correct. Unless you have a very unusual setup, the ServicePackFiles folder is not searched. This means that you keep an useless copy of your dll, and need to copy it to every project folder to run your programs.
<WINDOWS>\system32 is a better place, because then you actually use the dll as a "shared" library.
As a sidenote to 1) one might add glext.h and wglext.h, and you may want to use the gl.h/glu.h versions that you get either from SGI, nVidia, or ATI - if you intend to use more than only OpenGL 1.2 - for a basic GLUT demo, it does not matter, though.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Code Blocks Error Message with GLUT
« Reply #13 on: October 05, 2005, 06:42:11 pm »
Quote
Speaking of GLUT alternatives, GLFW is a quite cool product (not only a OpenGL toolkit, but includes many things like keyboard and joystick handling, as well as threading/messaging). Personally, I recommend this as the toolkit of choice, as it is really easy to use, small, zlib-licensed, and it includes everything you probably need.
Strangely, nobody seems to really use GLFW for some reason, which is a shame (I know of no serious project using it).

I couldn't say it better. GLFW rocks! :)
Be patient!
This bug will be fixed soon...

sethjackson

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #14 on: October 05, 2005, 06:44:32 pm »
Maybe you should try to debug the code....

I would debug for you but I dont have glut.

I really don't see anything wrong but, I'm not a very good programmer (yet)  :lol:.

Anyways, thomas is right the glut dll should be in <WINDOWS>\system32.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Code Blocks Error Message with GLUT
« Reply #15 on: October 05, 2005, 06:53:54 pm »
This seems rather interesting. Thomas, perhaps you could do some postings in glut-related forums and present a "Don't use GLUT" or "Use GLFW" initiative? Or at least ask why people don't use glfw...

himaja

  • Guest
program crashes with a Windows error message
« Reply #16 on: October 06, 2005, 07:11:21 am »

"The dynamic link library glut32.dll could not be found in C:\................................."very long file path which starts with where my cpp file sits and adds all these others weird C:\ paths to it.  What is wrong now?
That means you have to either copy the dll into the same directory where your program is (happens to be your project folder), or anywhere in your  PATH so the system can find it (most people use C:\windows or C:\windows\system32 for that matter).

I have copied the DLL to the same directory.  Now when i compile and run, i don't but that error anymore, but now it seems to crash.  I the the message, my application has generated errors and will be closed by windows, an error report is being created.  Whats the deal with that now?

Thanks everyone for responding and helping me out. I am now having the "program crashes with a Windows error message" right now - my code is really simple, just a downloaded tutorial to try out GLUT:

#include <gl/glut.h>

void renderScene(void) {
   glClear(GL_COLOR_BUFFER_BIT);
   glBegin(GL_TRIANGLES);
      glVertex3f(-0.5,-0.5,0.0);
      glVertex3f(0.5,0.0,0.0);
      glVertex3f(0.0,0.5,0.0);
   glEnd();
   glFlush();
}

int main(int argc, char **argv) {
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
   glutInitWindowPosition(100,100);
   glutInitWindowSize(320,320);
   glutCreateWindow("3D Tech- GLUT Tutorial");
   glutDisplayFunc(renderScene);
   glutMainLoop();
   return 0;
}

Also, I have been trying out GLUT because I want to create some simple GUIs for the program I am working on, along with some graphics and 3-D modelling, and GOOGLE suggested GLUT :) I would really appreciate it f anyone can suggest a better package for building Windows, buttons, menus etc.

Thanks,
Himaja.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: program crashes with a Windows error message
« Reply #17 on: October 06, 2005, 01:14:45 pm »
[...] building Windows, buttons, menus etc.
GLUT does not build any buttons or menus (you can create popup menus, but not a "menu" in the normal sense).

If you want something very similar to GLUT (maybe because you already spent time learning it), you are off best with freeglut (http://freeglut.sourceforge.net).
If you want a really good lightweight OpenGL toolkit, but you don't need popup menus and rather useless geometric modelling functions (like glutWireCube), then GLFW (http://glfw.sourceforge.net) is certainly the best choice.

If you absolutely must have menus and buttons and OpenGL, you will need to use either FLTK (http://www.fltk.org) or wxWidgets (http://www.wxwidgets.org).
wxWidgets has a very nice looking web page and a lot of shining features, but it is an ugly clumsy beast, painful to build and really huge. Also note that wxWidgets breaks STL by redefining new in a macro. If you have the habit to use STL, you must #undef new first (see wxWidgets FAQ).
FLTK looks like crap when you visit their website, but it really does a good job. It is small, lightweight, and easy to program with. There is a RAD editor coming with it, too. The 1.1x branch is 'stable', and 2.0 is 'alpha'. Building is nearly as painful as building wxWidgets, but there are binary DevPaks ;)

If you want to create windows, buttons, and menus inside your OpenGL context, you might want to look at GLUI (http://www.nigels.com/glt/glui) or at Crazy Eddie's GUI. The latter was still quite awful when I last looked at it a year or so ago, but it now ships with OGRE, so I guess that it has been drastically improved.

EDIT:
The code above looks like it should work. There is only one mistake in it, but that cannot possibly cause a crash. You forgot to set a vertex colour, so it would probably render all black. Are you maybe using some weird optimisation options (regparam comes to my mind), and have you made sure you use pristine versions of the GLUT library files? Maybe you experience DLL hell?
« Last Edit: October 06, 2005, 01:26:09 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

himaja

  • Guest
Re: program crashes with a Windows error message
« Reply #18 on: October 10, 2005, 06:32:17 pm »



Thank you for all the info about the various toolkits :) I decided to give up on GLUT (since it is still crashing without showing any output - anyone know a solution to that????) and go with WxWidgets instead. glut DOES seem to be DLL hell, overall. I am an experienced PROGRESS developer trying to get a software completed in C++, and I must say that Code::Blocks is a really great tool to use. And this forum is a godsend!!! Thank you, everyone, for helping out.
Himaja.

Offline petsagouris

  • Single posting newcomer
  • *
  • Posts: 5
    • arhitektonas
Re: Code Blocks Error Message with GLUT
« Reply #19 on: November 12, 2008, 02:14:02 pm »
I know I am digging an old thread (dead even), but I wanted to post some corrections to the procedure for setting up ol'n'dead GLUT on Code::Blocks and MinGW.

Follow through the tutorial on the Lawrence Goetz page. Before you try compiling the test project edit the following

in glut.h

on line 10 change
Code
# if 0 
to
Code
# if (_WIN_ALL)
Then go in the Project -> Build Options... ->#defines and add : _WIN_ALL
This should correct the error: redeclaration of C++ built-in type `short'

on line 100 add
Code
#define GLUT_DISABLE_ATEXIT_HACK
This should correct the warning: 'int glutCreateMenu_ATEXIT_HACK(void (*)(int))' defined but not used

slowcook

  • Guest
Re: Code Blocks Error Message with GLUT
« Reply #20 on: December 03, 2009, 02:58:16 pm »
I just had this problem (Running windows with MinGW) and fixed it by adding

#include <windows.h>

to the project file.

Edit: the "C:/Program Files/CodeBlocks/include/GL/glut.h:50: error: redeclaration of C++ built-in type `short'" problem
« Last Edit: December 03, 2009, 03:01:04 pm by slowcook »