Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Trouble compiling "my" OpenGL program *Not solved!*


  • Please log in to reply

#1
magnus80a

magnus80a

    Member

  • Member
  • PipPip
  • 10 posts
Hi!

I'm trying to learn the basics of OpenGL, but is stuck trying to compile Sierpinski's Gasket program. I'm using Dev-cpp (latest version) and MingGW through it as compiler. When I try to compile I get the following error messages:

1 C:\Documents and Settings\Magnus Olsson\Mina dokument\Egna projekt\OpenGL\test.cpp In file included from test.cpp 
43 C:\Program\Dev-Cpp\include\GL\glut.h redeclaration of C++ built-in type `short' 
1 C:\Documents and Settings\Magnus Olsson\Mina dokument\Egna projekt\OpenGL\test.cpp In file included from test.cpp

I'm not sure how to resolve this as it seems like there's a conflict in glut.h and I'm not sure if I should alter anything in a header file I haven't written myself... Has anyone encountered this problem before or know how to deal with it?

This is the code I've written (copied from my graphics book) so far:
#include <GL/glut.h>
using namespace std;
void myinit();
void display();

int main(int argc, char **argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(500,500);
	glutInitWindowPosition(0,0);
	glutCreateWindow("Simple OpenGL Example");
	glutDisplayFunc(display);
	myinit();
	glutMainLoop();
	
	return 0;
}

void myinit(void) {
	/* Attributes */
	glClearColor(1.0, 1.0, 1.0, 1.0);							   // White
	glColor3f(1.0, 0.0, 0.0);									   // Red
	
	/* Set up viewing */
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, 500.0, 0.0, 500.0);
	glMatrixMode(GL_MODELVIEW);
}

void display(void) {
	typedef GLfloat point2[2];									  // Define a point data type
	
	point2 vertices[3]={{0.0, 0.0}, {250.0, 500.0}, {500.0, 0.0}};  // Triangle
	
	int i, j , k;
	int rand();
	point2 p={75.0,75.0};										   // Arbitrary point inside the triangle
	glClear(GL_COLOR_BUFFER_BIT);								   // Clear the window
	
	/* Compute and output 5000 new points */
	for (k=0;k<5000;k++) {
		j = rand()%3;											   // Pick a random vertex
		
		/* Compute halfway between vertex and old point */
		p[0]=(p[0]+vertices[j][0])/2.0;
		p[1]=(p[1]+vertices[j][1])/2.0;
		
		/* Plot point */
		glBegin(GL_POINTS);
			glVertex2fv(p);
		glEnd();
	}   
}

Edited by magnus80a, 11 December 2005 - 04:05 PM.

  • 0

Advertisements


#2
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts
Hi Magnus,

The problem area in glut.h looks like this:
#  ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#   define _WCHAR_T_DEFINED
#  endif
Dev-cpp is complaining because in your code, _WCHAR_T_DEFINED is not yet defined, so the typedef code is being compiled. However, wchar_t is defined, so the compiler complains. For some reason it complains about short instead of wchar_t, but the real problem is that wchar_t is already defined.

To solve this, you could try putting "#define _WCHAR_T_DEFINED" just before you include glut.h. You might continue running into similiar problems. If so, remove the #define statement include stdlib.h before glut.h. Hopefully that will take care of everything.

Good luck,
Ricci
  • 0

#3
magnus80a

magnus80a

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts

To solve this, you could try putting "#define _WCHAR_T_DEFINED" just before you include glut.h. You might continue running into similiar problems. If so, remove the #define statement include stdlib.h before glut.h. Hopefully that will take care of everything.

Thanks for the reply! :)
I added the line #define _WCHAR_T_DEFINED to the top of my code and it certainly did something. The error message vanished and only left the following:
C:\Documents and Settings\Magnus Olsson\Mina dokument\Egna projekt\OpenGL\Makefile.win [Build Error]  [opengl.exe] Error 1
Unfortunately, this isn't very informative. Maybe it's dev-cpp that's causing it? Are there any other free software I can use instead? I've tried googling for a compiler, but haven't found any I deem good.
For example if I try to compile the code with Digital Mars Compiler I get the following error message (after doing your "fix").
> dmc test.cpp
using namespace std;
test.cpp(3) : Error: Undefined identifier 'std'
--- errorlevel 1
:tazz:
  • 0

#4
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts

I added the line #define _WCHAR_T_DEFINED to the top of my code and it certainly did something. The error message vanished and only left the following:

C:\Documents and Settings\Magnus Olsson\Mina dokument\Egna projekt\OpenGL\Makefile.win [Build Error]  [opengl.exe] Error 1

Try
#include<iostream>
#include "glut.h"
instead of
#define _WCHAR_T_DEFINED
#include "glut.h"
In your original post, you have "using namespace std;" but you don't ever include a header that defines the namespace std. If you include iostream before glut.h, it might fix the problems glut is having, and it will give you the std namespace too.

For example if I try to compile the code with Digital Mars Compiler I get the following error message (after doing your "fix").

> dmc test.cpp
using namespace std;
test.cpp(3) : Error: Undefined identifier 'std'
--- errorlevel 1

This is because of the problem that I already mentioned. You have a line of code that says "using namespace std;", but you don't include a header that defines the std namespace. Either remove the using line or include iostream or something that defines std.

-Ricci
  • 0

#5
magnus80a

magnus80a

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts
Thanks again! :)

Doing the above changes like this:
#include <iostream>
#include <GL/glut.h>
using namespace std;
.
.
.

gives the following error message in dev-cpp:
C:\Documents and Settings\Magnus Olsson\Mina dokument\Egna projekt\OpenGL\Makefile.win [Build Error] [opengl.exe] Error 1

and this using DMC:
Fatal error: unable to open input file 'iostream'
--- errorlevel 1


I've checked and iostream is in the include folder for both compilers (DMC and dev-cpp (MingGW)). I haven't had any trouble with iostream before :tazz:
  • 0

#6
ricci

ricci

    Member

  • Member
  • PipPip
  • 64 posts
I'm afraid I'm stumped here. I've done some openGL programming, but it was with Visual Studio. I tried to set something up in Dev-cpp just now, but I didn't have any luck at all. Sorry I couldn't be more help.

-Ricci
  • 0

#7
magnus80a

magnus80a

    Member

  • Topic Starter
  • Member
  • PipPip
  • 10 posts
No problem, I'll make it work somehow :) (Somebody is bound to have had the same problem...)
Thanks for trying, you've broadened my view of namespace :tazz:

Edited by magnus80a, 07 December 2005 - 09:44 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP