Thread: I think my compiler hates me

  1. #1
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96

    I think my compiler hates me

    This is starting to happen more and more as the example programs get more and more involved with my skill level BUT.... here my problem

    I come across example code freequently as you do, now im talking whole program code but when i put it into my complier it either comes up with a trillion errors weather there sytntax or linker errors?

    I'm using Dev C++ 4 but anyway heres an example of some code I tryed to get to work just now... sorry it's a bit big

    Code:
    #include <GL/gl.h>
    #include <GL/glut.h>
    
    void display(void)
    {
    /*  clear all pixels  */
        glClear (GL_COLOR_BUFFER_BIT);
    
    /*  draw white polygon (rectangle) with corners at
     *  (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)  
     */
        glColor3f (1.0, 1.0, 1.0);
        glBegin(GL_POLYGON);
            glVertex3f (0.25, 0.25, 0.0);
            glVertex3f (0.75, 0.25, 0.0);
            glVertex3f (0.75, 0.75, 0.0);
            glVertex3f (0.25, 0.75, 0.0);
        glEnd();
    
    /*  don't wait!  
     *  start processing buffered OpenGL routines 
     */
        glFlush ();
    }
    
    void init (void) 
    {
    /*  select clearing (background) color       */
        glClearColor (0.0, 0.0, 0.0, 0.0);
    
    /*  initialize viewing values  */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    }
    
    /* 
     *  Declare initial window size, position, and display mode
     *  (single buffer and RGBA).  Open window with "hello"
     *  in its title bar.  Call initialization routines.
     *  Register callback function to display graphics.
     *  Enter main loop and process events.
     */
    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize (250, 250); 
        glutInitWindowPosition (100, 100);
        glutCreateWindow ("hello");
        init ();
        glutDisplayFunc(display); 
        glutMainLoop();
        return 0;   /* ISO C requires main to return int. */
    }
    And it returns about 30 of these errors:

    C:\DEV-C_~1\Include\GL\gl.h:1135: syntax error before `void'
    warning: data definition has no type or storage class

  2. #2
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Your error comes from the included files so there might be something wrong with your installation.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Given that all of the functions in GL/gl.h are prefixed with GLAPI:
    Code:
    GLAPI void APIENTRY glClearIndex( GLfloat c );
    GLAPI void APIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
    GLAPI void APIENTRY glClear( GLbitfield mask );
    GLAPI void APIENTRY glIndexMask( GLuint mask );
    GLAPI void APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha );
    GLAPI void APIENTRY glAlphaFunc( GLenum func, GLclampf ref );
    GLAPI void APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor );
    GLAPI void APIENTRY glLogicOp( GLenum opcode );
    GLAPI void APIENTRY glCullFace( GLenum mode );
    GLAPI void APIENTRY glFrontFace( GLenum mode );
    GLAPI void APIENTRY glPointSize( GLfloat size );
    GLAPI void APIENTRY glLineWidth( GLfloat width );
    /* ... */
    I'd guess that GLAPI is not defined for some reason. Here's where GLAPI is defined (in the same header file):
    Code:
    /* GLAPI, part 1 (use WINGDIAPI, if defined) */
    #if defined(__WIN32__) && defined(WINGDIAPI)
    #  define GLAPI WINGDIAPI
    #endif
    
    /* GLAPI, part 2 */
    #if !defined(GLAPI)
    #  if defined(_MSC_VER)                        /* Microsoft Visual C++ */
    #    define GLAPI __declspec(dllimport)
    #  elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */
    #    define GLAPI __stdcall
    #  else                                        /* Others (e.g. MinGW, Cygwin, non-win32) */
    #    define GLAPI extern
    #  endif
    #endif
    You could try defining GLAPI yourself, according to what it should be for your compiler, before you #include GL/gl.h. It might work, I don't know.

    (Note that your header files might be different.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    The code in the first post compiles just fine for me. I don't see the issue. It produces a solid white quad. You might want to drop Dev-C++ 4 and go with version 5 even if it is a beta - it'll have never versions of everything. Or you could just compile it like I did - command-line.

    Code:
    gcc test.c -o test.exe -lglut32 -lopengl32 -lglu32 -Wall
    Only complaint was my fault - no newline.

  5. #5
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96

    Glut

    Iv'e nailed it down to an installation problem because when i try to run this:

    Code:
    #include <gl/glut.h>
    int main(){}
    it yells at me still.
    I downloaded the files and put them in the appropriote directories (sorry spelling) like lib files in the lib folder and .h in the include/gl folder but is there more i have to do for the installation because iv'e found a few docs on the net saying that with VC you have to set it up from within the program... i dont know i'm more then lost here and i have no clue why it's not working for me.
    Last edited by Matty_Alan; 07-15-2007 at 01:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM