Need Help with glut, [Code::Blocks and mingw]

So, I’ve been trying to get something, ANYTHING related to openGl to work in Code::Blocks. its been three days trying to get any of the many tutorials from NEHE’s to the video Tutorials.

None of the setup tutorials seem to work however. mingw seems unhappy with any of the sourcecode I feed it from these sites.

If someone who knows could help, I would greatly appreciate it.


As far as what I am working with right now? I’ve linked things as best I can doing the following:

In settings->compiler and debugger
under linker settings I have added the paths to the glut32.lib and to the glut.lib

Under search directories I point to
[for Compiler tab]
D:\libRsc\oGL\glut\include
[Basically, I made an include folder, put a GL folder in here with the glut.h]

[for Linker tab]
D:\libRsc\oGL\glut\lib

I have also tried doing the above, but keeping the files as I got them in the download, all within the glut folder, and then just point everything to the glut folder.

The code I’ve tried using is the source code of NeHe, and also the built in sample code when you run the Code::Blocks project wizard for Glut apps [and I also pointed the wizard to the location of Glut there to]

below is the code I got from the wizard

/*
 * GLUT Shapes Demo
 *
 * Written by Nigel Stewart November 2003
 *
 * This program is test harness for the sphere, cone
 * and torus shapes in GLUT.
 *
 * Spinning wireframe and smooth shaded shapes are
 * displayed until the ESC or q key is pressed.  The
 * number of geometry stacks and slices can be adjusted
 * using the + and - keys.
 */

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>

static int slices = 16;
static int stacks = 16;

/* GLUT callback Handlers */

static void resize(int width, int height)
{
    const float ar = (float) width / (float) height;

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}

static void display(void)
{
    const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
    const double a = t*90.0;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

    glPushMatrix();
        glTranslated(-2.4,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidSphere(1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(0,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidCone(1,1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(2.4,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidTorus(0.2,0.8,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-2.4,-1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutWireSphere(1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(0,-1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutWireCone(1,1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(2.4,-1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutWireTorus(0.2,0.8,slices,stacks);
    glPopMatrix();

    glutSwapBuffers();
}


static void key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case 27 :
        case 'q':
            exit(0);
            break;

        case '+':
            slices++;
            stacks++;
            break;

        case '-':
            if (slices>3 && stacks>3)
            {
                slices--;
                stacks--;
            }
            break;
    }

    glutPostRedisplay();
}

static void idle(void)
{
    glutPostRedisplay();
}

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();

    return EXIT_SUCCESS;
}

Now, no matter what bit of glut code I try to use, I get the same error,

obj\Debug\main.o||In function _Z6resizeii':| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|34|undefined reference to __imp__glViewport’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|35|undefined reference to __imp__glMatrixMode'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|36|undefined reference to __imp__glLoadIdentity’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|37|undefined reference to __imp__glFrustum'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|39|undefined reference to __imp__glMatrixMode’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|40|undefined reference to __imp__glLoadIdentity'| obj\Debug\main.o||In function _Z7displayv’:expressionless:
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|45|undefined reference to _glutGet'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|48|undefined reference to __imp__glClear’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|49|undefined reference to __imp__glColor3d'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|51|undefined reference to __imp__glPushMatrix’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|52|undefined reference to __imp__glTranslated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|53|undefined reference to __imp__glRotated’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|54|undefined reference to __imp__glRotated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|55|undefined reference to _glutSolidSphere’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|56|undefined reference to __imp__glPopMatrix'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|58|undefined reference to __imp__glPushMatrix’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|59|undefined reference to __imp__glTranslated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|60|undefined reference to __imp__glRotated’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|61|undefined reference to __imp__glRotated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|62|undefined reference to _glutSolidCone’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|63|undefined reference to __imp__glPopMatrix'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|65|undefined reference to __imp__glPushMatrix’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|66|undefined reference to __imp__glTranslated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|67|undefined reference to __imp__glRotated’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|68|undefined reference to __imp__glRotated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|69|undefined reference to _glutSolidTorus’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|70|undefined reference to __imp__glPopMatrix'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|72|undefined reference to __imp__glPushMatrix’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|73|undefined reference to __imp__glTranslated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|74|undefined reference to __imp__glRotated’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|75|undefined reference to __imp__glRotated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|76|undefined reference to _glutWireSphere’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|77|undefined reference to __imp__glPopMatrix'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|79|undefined reference to __imp__glPushMatrix’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|80|undefined reference to __imp__glTranslated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|81|undefined reference to __imp__glRotated’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|82|undefined reference to __imp__glRotated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|83|undefined reference to _glutWireCone’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|84|undefined reference to __imp__glPopMatrix'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|86|undefined reference to __imp__glPushMatrix’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|87|undefined reference to __imp__glTranslated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|88|undefined reference to __imp__glRotated’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|89|undefined reference to __imp__glRotated'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|90|undefined reference to _glutWireTorus’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|91|undefined reference to __imp__glPopMatrix'| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|93|undefined reference to _glutSwapBuffers’|
obj\Debug\main.o||In function _Z3keyhii':| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|120|undefined reference to _glutPostRedisplay’|
obj\Debug\main.o||In function _Z4idlev':| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|125|undefined reference to _glutPostRedisplay’|
obj\Debug\main.o||In function main':| D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|142|undefined reference to _glutInit’|
D:\My Documents\SyncFolder\programming\openGLRelated\projects\glutTest\main.cpp|143|undefined reference to `_glutInitWindowSize’|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options…|
||=== Build finished: 50 errors, 0 warnings ===|

Now, it seems to me that the issue is that its some how failing to make use of openGL commands, possibly via glut. I’m not sure where all the imp bits come from, as its no where in the code. The glut.h I’m using is the very same one you get from the download

I would very much so like to try using glut but so far, I haven’t been able to do anything other than struggle with error after error.

I really just want to try writing some code already. This is just frustrating

[edit]
Ah, now, also, if I take ALL code out and leave just the includes, I get an error where the glut.h is doing this:

typedef unsigned short wchar_t;

This gets me the error: C:\Program Files\CodeBlocks\MinGW\include\GL\glut.h|43|error: redeclaration of C++ built-in type `short’|

under linker settings I have added the paths to the glut32.lib and to the glut.lib

Don’t forget opengl32.lib …

Mmm, it looks like the wizard handled that for me.
The projects linker settings has this setup:

glut32
opengl32
glu32
winmm
gdi32

Also, I fixed the weird typedef for the short, and now it gives me this

C:\Program Files\CodeBlocks\MinGW\lib\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `_WinMain@16’|

I’m not even sure how I might go around fixing this.
Up till now it seemed like I wasn’t linking something correctly

[edit]

Out of curiosity, is there an easier way to go about this? I have no particular tie to using this particular IDE and compiler. I just don’t know anything better.

I’ve tried running through with a copy of VSC8 I had and it just flat out refused to even try and build anything… Something about being unable to build an rc.exe and rather rude comments about my mother.

Strange… I need only glut32,opengl32,glu32 to link. Maybe try to link mingw32 too. Don’t forget, the order matters.
You get that error, if you don’t have a main() function, but you have, so I have no idea.

Well, its about time for it anyways, so I’m going to try a complete reinstall.

I think perhaps there may be an issue with my computer anyways. Visual Studio 8 can’t find ANY standard headers [<iostream>, <stdio> etc.] and what have it.

If I uninstall and reinstall code blocks nothing has changed… So… Gonna reinstall XP and see if anything better comes up.

Visual Studio 8 can’t find ANY standard headers [<iostream>, <stdio> etc.] and what have it.

For reasons I do not understand, it needs an additional download called something like “Microsoft Platform SDK”.

On the main() versus WinMain, the first is what you need used for a classic build, and when you use GLUT. The second is when you build a win32 project. Try to toggle this somewhere on the project settings.

Well, I just finished reinstalling XP and set up VS8 [this time I tried the express version, not the full]

Things worked first time, and I didn’t install any SDK either… I think perhaps there was an issue with some of the .dlls in the system directory perhaps… I dunno what else it might be. I hadn’t messed with VS’s paths or anything

Just got home from work so I’ll try using glut tommorow

Thanks for the help so far :slight_smile: