Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: MinGW compilation for the Orange-Book

  1. #1
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    7

    MinGW compilation for the Orange-Book

    Hello, I'm having a bit of difficulty compiling and running the tutorials of The OpenGL Programming Guide with MinGW. I know the code is incomplete but I'd still like to at least be able to run some OpenGL code to see if I've set up OpenGL correctly as well as be able to experiment with OpenGL a bit also.

    I saw there was a Makefile in the main directory but when I try and invoke make I get this error:
    Code :
    for d in 01 10 ; do ( cd $d ; mingw32-make default ) ; done
    d was unexpected at this time.
    Makefile:11: recipe for target 'default' failed
    mingw32-make: *** [default] Error 255

    The code is on the website, www.opengl-redbook.com. I'd just like to know how to compile the code from the chapters like Chapter 3 through MinGW but have no idea where to start.

    As for my set-up I've set up FreeGlut from the lazyfoo tutorials.

    This is the second third-party library I've used, SDL being the first through the spoon-feeding of lazyfoo tutorials. Any help or advice would be vastly appreciated.

  2. #2
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    7
    Ok, I hate swapping the thread topic a bit but here's what I've been trying to do. Under the book the first example is as follows:
    Code :
    ///////////////////////////////////////////////////////////////////////
    //
    // triangles.cpp
    //
    ///////////////////////////////////////////////////////////////////////
     
    #include <iostream>
    using namespace std;
     
    #include "vgl.h"
    #include "LoadShaders.h"
     
    enum VAO_IDs { Triangles, NumVAOs };
    enum Buffer_IDs { ArrayBuffer, NumBuffers };
    enum Attrib_IDs { vPosition = 0 };
     
    GLuint  VAOs[NumVAOs];
    GLuint  Buffers[NumBuffers];
     
    const GLuint  NumVertices = 6;
     
    //---------------------------------------------------------------------
    //
    // init
    //
     
    void 
    init(void)
    {
        glGenVertexArrays(NumVAOs, VAOs);
        glBindVertexArray(VAOs[Triangles]);
     
        GLfloat  vertices[NumVertices][2] = {
            { -0.90, -0.90 },  // Triangle 1
            {  0.85, -0.90 },
            { -0.90,  0.85 },
            {  0.90, -0.85 },  // Triangle 2
            {  0.90,  0.90 },
            { -0.85,  0.90 }
        };
     
        glGenBuffers(NumBuffers, Buffers);
        glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
                     vertices, GL_STATIC_DRAW);
     
        ShaderInfo  shaders[] = {
            { GL_VERTEX_SHADER, "triangles.vert" },
            { GL_FRAGMENT_SHADER, "triangles.frag" },
            { GL_NONE, NULL }
        };
     
        GLuint program = LoadShaders(shaders);
        glUseProgram(program);
     
        glVertexAttribPointer(vPosition, 2, GL_FLOAT,
                              GL_FALSE, 0, BUFFER_OFFSET(0));
        glEnableVertexAttribArray(vPosition);
    }
     
    //---------------------------------------------------------------------
    //
    // display
    //
     
    void 
    display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);
     
        glBindVertexArray(VAOs[Triangles]);
        glDrawArrays(GL_TRIANGLES, 0, NumVertices);
     
        glFlush();
    }
     
    //---------------------------------------------------------------------
    //
    // main
    //
     
    int 
    main(int argc, char** argv)
    {
         glutInit(&argc, argv);
         glutInitDisplayMode(GLUT_RGBA);
         glutInitWindowSize(512, 512);
         glutInitContextVersion(4, 3);
         glutInitContextProfile(GLUT_CORE_PROFILE);
         glutCreateWindow(argv[0]);
     
         if (glewInit()) {
             cerr << "Unable to initialize GLEW ... exiting" << endl;
             exit(EXIT_FAILURE);
         }
     
         init();
     
         glutDisplayFunc(display);
     
         glutMainLoop();
    }

    With the two headers being in the source code on the website. Here is my makefile:
    Code :
    #OBJS specifies which files to compile as part of the project
    OBJS = triangles.cpp
     
    #OBJ_NAME specifies the name of our exectuable
    OBJ_NAME = triangles
     
    #CC specifies which compiler we're using
    CC = g++
     
    #INCLUDE_PATHS specifies the additional include paths we'll need
    INCLUDE_PATHS = -IC:\mingw_dev_lib\freeglut\include
     
    #LIBRARY_PATHS specifies the additional library paths we'll need
    LIBRARY_PATHS = -LC:\mingw_dev_lib\freeglut\lib
     
    #COMPILER_FLAGS specifies the additional compilation options we're using
    # -w suppresses all warnings
    # -Wl,-subsystem,windows gets rid of the console window
    COMPILER_FLAGS = -w -Wl,-subsystem,windows
     
    #LINKER_FLAGS specifies the libraries we're linking against
    LINKER_FLAGS = -lOpenGL32 -lglu32 -lfreeGLUT
     
    #This is the target that compiles our executable
    all : $(OBJS)
    	$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

    With all this I get undefined references as follows:
    Code :
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x1c): undefine
    d reference to `__glutInitWithExit'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x37): undefine
    d reference to `__glutCreateWindowWithExit'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x52): undefine
    d reference to `__glutCreateMenuWithExit'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x65): undefine
    d reference to `__glewGenVertexArrays'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x7f): undefine
    d reference to `__glewBindVertexArray'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0xa6): undefine
    d reference to `__glewGenBuffers'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0xc0): undefine
    d reference to `__glewBindBuffer'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0xdb): undefine
    d reference to `__glewBufferData'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x135): undefin
    ed reference to `LoadShaders'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x13e): undefin
    ed reference to `__glewUseProgram'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x14e): undefin
    ed reference to `__glewVertexAttribPointer'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x187): undefin
    ed reference to `__glewEnableVertexAttribArray'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x1c0): undefin
    ed reference to `__glewBindVertexArray'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x227): undefin
    ed reference to `glutInitDisplayMode'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x23b): undefin
    ed reference to `glutInitWindowSize'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x24f): undefin
    ed reference to `glutInitContextVersion'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x25b): undefin
    ed reference to `glutInitContextProfile'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x26d): undefin
    ed reference to `glewInit@0'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x2b8): undefin
    ed reference to `glutDisplayFunc'
    C:\Users\Alex\AppData\Local\Temp\ccbYi3fS.o:triangles.cpp:(.text+0x2bd): undefin
    ed reference to `glutMainLoop'
    c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\A
    lex\AppData\Local\Temp\ccbYi3fS.o: bad reloc address 0x0 in section `.ctors'
    collect2.exe: error: ld returned 1 exit status
    Makefile:26: recipe for target 'all' failed
    mingw32-make: *** [all] Error 1

    Could someone please help me run an OpenGL program using MinGW or show me an alternative source for learning OpenGL under Windows with MinGW that doesn't employ the deprecated pipeline?

  3. #3
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    7
    UPDATE:
    After setting up Visual Studio with glut and glew to run the code below I was also able to get MinGW to set up the same code below as well. The big thing is that I'm using the freeglut directories of VS rather than MinGW for both as the MinGW lib folder contains .a files which seem to be unrecognized by MinGW on windows.

    Code :
    #include <GL\glew.h>
    #include <GL\freeglut.h>
    #include <cstdio>
    #include <iostream>
     
    using namespace std;
     
    void changeViewport(int w, int h) {
    	glViewport(0, 0, w, h);
    }
     
    void render() {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glutSwapBuffers();
    }
     
    int main(int argc, char * argv[])
    {
    	// Initialize GLUT
    	glutInit(&argc, argv);
     
    	// Set up some memory buffers for our display
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    	// Set the window size
    	glutInitWindowSize(800, 600);
    	// Create the window with the title "Hello, GL"
    	glutCreateWindow("Hello GL");
    	// Bind the two functions (above) to respond when necessary
    	glutReshapeFunc(changeViewport);
    	glutDisplayFunc(render);
     
    	// Very important! This initializes the entry points in the OpenGL driver so we can
    	// call the function in the API.
    	GLenum err = glewInit();
    	if (GLEW_OK != err) {
    		fprintf(stderr, "GLEW error");
    		return 1;
    	}
     
    	// Start up a loop that runs in the background (you never see it)
    	glutMainLoop();
    	return 0;
    }

    Now with visual studio I didn't have to use #include <cstdio>, I'm assuming that has something to do with the windows directory being in the include path perhaps?

    Going back to the original code I get some new errors for both VS and MinGW.

    Under VS I get this something along the lines of an error with freeglut and static linking.

    Under MinGW I get this:
    Code :
    1>c:\freeglut\include\gl\freeglut_std.h(68): fatal error C1189: #error :  Static linking is not supported with this build. Please remove the FREEGLUT_STATIC preprocessor directive, or download the source code from http://freeglut.sf.net/ and build against that.

    So I've decided to ditch that code in exchange for the more simple one for now in diagnosing my problem.

    When I try MinGW on the new source I get a blurb of this:

    Code :
    In file included from C:\freeglut\include/GL/freeglut.h:17:0,
                     from vgl.h:37,
                     from triangles.cpp:9:
    C:\freeglut\include/GL/freeglut_std.h:605:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_std.h:606:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_std.h:607:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_std.h:614:33: error: expected initializer before
     'glutInit_ATEXIT_HACK'
    C:\freeglut\include/GL/freeglut_std.h:616:32: error: expected initializer before
     'glutCreateWindow_ATEXIT_HACK'
    In file included from C:\freeglut\include/GL/freeglut.h:17:0,
                     from vgl.h:37,
                     from triangles.cpp:9:
    C:\freeglut\include/GL/freeglut_std.h:618:32: error: expected initializer before
     'glutCreateMenu_ATEXIT_HACK'
    In file included from C:\freeglut\include/GL/freeglut.h:18:0,
                     from vgl.h:37,
                     from triangles.cpp:9:
     
    C:\freeglut\include/GL/freeglut_ext.h:186:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:187:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:188:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:216:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:217:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:218:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:223:1: error: 'FGAPI' does not name a type
     
    C:\freeglut\include/GL/freeglut_ext.h:224:1: error: 'FGAPI' does not name a type
     
    triangles.cpp: In function 'int main(int, char**)':
    triangles.cpp:84:26: error: 'glutInit_ATEXIT_HACK' was not declared in this scop
    e
    triangles.cpp:85:35: error: 'glutInitDisplayMode' was not declared in this scope
     
    triangles.cpp:86:33: error: 'glutInitWindowSize' was not declared in this scope
    triangles.cpp:87:33: error: 'glutInitContextVersion' was not declared in this sc
    ope
    triangles.cpp:88:46: error: 'glutInitContextProfile' was not declared in this sc
    ope
    triangles.cpp:89:30: error: 'glutCreateWindow_ATEXIT_HACK' was not declared in t
    his scope
    triangles.cpp:98:29: error: 'glutDisplayFunc' was not declared in this scope
    triangles.cpp:100:19: error: 'glutMainLoop' was not declared in this scope
    Makefile:26: recipe for target 'all' failed
    mingw32-make: *** [all] Error 1

    The commong line of error being this:
    Code :
    fatal error C1189: #error :  Static linking is not supported with this build. Please remove the FREEGLUT_STATIC preprocessor directive, or download the source code from http://freeglut.sf.net/ and build against that.

    Could someone shed some light about how to fix this? It seems like just blatantly removing #define FREEGLUT_STATIC doesn't fix the problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •