Welcome Guest ( Log In | Join )

Discover the best free computer help!
Learn more about Geeks to Go by taking the tour. Want to ask a question, reply to a topic, or remove all advertising? It's easy, fast and free. Join today!
Spyware, virus, trojan, fake security or privacy alerts? Please start with our malware cleaning guide.
     
 
Reply to this topicStart new topic
Trouble compiling "my" OpenGL program *Not solved!*, C++
magnus80a
post Dec 3 2005, 04:57 PM
Post #1


Member
**
Posts: 10
OS: Windows XP Pro



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:

CODE
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:
CODE

#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();
    }  
}


This post has been edited by magnus80a: Dec 11 2005, 04:05 PM
Go to the top of the page
 
+Quote Post
ricci
post Dec 5 2005, 12:27 PM
Post #2


Member
**
Posts: 64
OS: Windows XP



Hi Magnus,

The problem area in glut.h looks like this:
CODE
#  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
Go to the top of the page
 
+Quote Post
magnus80a
post Dec 5 2005, 01:30 PM
Post #3


Member
**
Posts: 10
OS: Windows XP Pro



QUOTE(ricci @ Dec 5 2005, 07:27 PM) [snapback]471743[/snapback]

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! smile.gif
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:
CODE
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").
CODE
> dmc test.cpp
using namespace std;
test.cpp(3) : Error: Undefined identifier 'std'
--- errorlevel 1

confused1.gif
Go to the top of the page
 
+Quote Post
ricci
post Dec 5 2005, 02:39 PM
Post #4


Member
**
Posts: 64
OS: Windows XP



QUOTE
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:
CODE
C:\Documents and Settings\Magnus Olsson\Mina dokument\Egna projekt\OpenGL\Makefile.win [Build Error]  [opengl.exe] Error 1

Try
CODE
#include<iostream>
#include "glut.h"
instead of
CODE
#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.

QUOTE
For example if I try to compile the code with Digital Mars Compiler I get the following error message (after doing your "fix").
CODE
> 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
Go to the top of the page
 
+Quote Post
magnus80a
post Dec 6 2005, 05:52 AM
Post #5


Member
**
Posts: 10
OS: Windows XP Pro



Thanks again! smile.gif

Doing the above changes like this:
CODE
#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 confused1.gif
Go to the top of the page
 
+Quote Post
ricci
post Dec 6 2005, 10:52 AM
Post #6


Member
**
Posts: 64
OS: Windows XP



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
Go to the top of the page
 
+Quote Post
magnus80a
post Dec 6 2005, 01:59 PM
Post #7


Member
**
Posts: 10
OS: Windows XP Pro



No problem, I'll make it work somehow smile.gif (Somebody is bound to have had the same problem...)
Thanks for trying, you've broadened my view of namespace happy.gif

This post has been edited by magnus80a: Dec 7 2005, 09:44 AM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


RSS Time is now: 8th January 2009 - 12:54 PM
Advertisements do not imply our endorsement of that product or service. The forum is run by volunteers who donate their time and expertise. We make every attempt to ensure that the help and advice posted is accurate and will not cause harm to your computer. However, we do not guarantee that they are accurate and they are to be used at your own risk.