Question

I am trying to run openGL on Dev C++. And I cannot get the code to run. I've tried everything on this site:

http://www.prinmath.com/csci5229/misc/DevC_OpenGL_for_Windows.pdf

My Operating system is windows 7-64 bit. I would use a different IDE if I could but my school insists that we use Dev C++.

here is the code that I am trying to run:

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


void init()
{
    glClearColor (1.0, 1.0, 1.0, 0.0); 

    glMatrixMode (GL_PROJECTION);       
    gluOrtho2D (0.0, 200.0, 0.0, 200.0); 
}

void lineSegment()
{
    glClear (GL_COLOR_BUFFER_BIT);  // Clear display window. color buffer

    glColor3f (0.0, 0.0, 0.0);     
int p1 [ ] = {40,80};
int p2 [ ] = {160, 80};
int p3 [ ] = {100, 40};
int p4 [ ] = {100, 160};
int p5 [ ] = {0, 80};
int p6 [ ] = {200, 200};
int p7 [ ] = {100, 0};
int p8 [ ] = {100,200 };
int p9 [ ] = {30, 30};
int p10 [ ] = {0, 0};

glBegin(GL_LINE_LOOP);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);

    glFlush ( );     
}

int main(int argc, char *argv[])
{
    glutInit (&argc, argv);                         // Initialize GLUT.
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);   // Set display mode, single buffering.
    glutInitWindowPosition (50, 100);   // Set top-left display-window position.
    glutInitWindowSize (400, 300);      // Set display-window width and height.
    glutCreateWindow ("An Example OpenGL Program"); // Create display window.

    init( );                            // Execute initialization procedure.
    glutDisplayFunc (lineSegment);       // Send graphics to display window.
    glutMainLoop ( );                    // Display everything and wait.

    //return EXIT_SUCCESS();
    return 0;   
}

And here is what the compile log says When I try to compile:

gcc.exe -D__DEBUG__ -c testLab.c -o testLab.o -I"C:/Dev-Cpp/include"    -pg -g3

windres.exe -i testProject_private.rc --input-format=rc -o testProject_private.res -O coff 

gcc.exe -D__DEBUG__ testLab.o testProject_private.res -o "testProject.exe" -L"C:/Dev-Cpp/lib" -mwindows -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32  -lgmon -pg  -g3 

/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x18a)C:\Dev-Cpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
:crt1.c: undefined reference to `__dyn_tls_init_callback'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x1be):crt1.c: undefined reference to `__cpu_features_init'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x1f1):crt1.c: undefined reference to `__chkstk_ms'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x376):crt1.c: undefined reference to `__mingw_glob'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x47d):crt1.c: undefined reference to `__mingw_glob'
testLab.o(.text+0x26): In function `glutInit_ATEXIT_HACK':
C:/Dev-Cpp/include/GL/glut.h:455: undefined reference to `_imp____glutInitWithExit@12'

testLab.o(.text+0x52): In function `glutCreateWindow_ATEXIT_HACK':
C:/Dev-Cpp/include/GL/glut.h:472: undefined reference to `_imp____glutCreateWindowWithExit@8'
testLab.o(.text+0x7e): In function `glutCreateMenu_ATEXIT_HACK':
C:/Dev-Cpp/include/GL/glut.h:518: undefined reference to `_imp____glutCreateMenuWithExit@8'
testLab.o(.text+0x26a): In function `main':
C:/Users/../testLab.c:43: undefined reference to `_imp__glutInitDisplayMode@4'
testLab.o(.text+0x283):C:/Users/../testLab.c:44: undefined reference to `_imp__glutInitWindowPosition@8'
testLab.o(.text+0x29c):C:/Users/../testLab.c:45: undefined reference to `_imp__glutInitWindowSize@8'
testLab.o(.text+0x2c1):C:/Users/../testLab.c:49: undefined reference to `_imp__glutDisplayFunc@4'
testLab.o(.text+0x2cb):C:/Users/../testLab.c:50: undefined reference to `_imp__glutMainLoop@0'
collect2: ld returned 1 exit status

make.exe: *** [testProject.exe] Error 1

Execution terminated
Was it helpful?

Solution

Looks like you're linking with wrong version of C-runtime (CRT).

  • If you have multiple versions of MinGW installed, show Dev-C++ where to find right includes and libs (check your PATH environment variable, MINGW_HOME environment variable and Dev-C++ compiler options). You must use CRT which ships with compiler.
  • Try to #include <windows.h> before other includes. It can fix dllimports stuff
  • Try to add -m32 flag to compiler command line (it will emit code for x86_32, in case if you are compiling with 64-bit compiler)
  • Ask your teacher how to fix it (it's his (her) job, and it's (s)he who choose to use 10 years old stuff)

Note, that latest version of Dev-C++ was released 22.02.2005. It includes GCC 3.4.2 released September 6, 2004. You must really ask your teachers why would they insist on using 9 years old IDE with 10 years old compiler. You can find maintained version of Dev-C++ here (it was picked up by another developer), and latest MinGW compiler here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top