7 Replies - 16933 Views - Last Post: 16 June 2010 - 03:10 PM Rate Topic: -----

#1 heyoman1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Why isnt this OpenGL program not working for me?

Posted 14 June 2010 - 04:35 PM

when i compile this code
#include <iostream>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>
using namespace std;

void display(void)
{
     // clear all pixels
     glClear(GL_COLOR_BUFFER_BIT);
     /* draw white polygon (rectangle) at corners
     (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.75, 0.25, 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 fuction 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();
     system("pause");
     return 0; // ISO C requires main to return int
 }




is gives me these errors
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  [Linker error] undefined reference to `[email protected]' 
  ld returned 1 exit status 



why is this happening?

extra info: Dev C++ is saved to a usb. the gl files stated in the code above is in Dev-Cpp\include\GL. i already tried to do the project -> param things, but the options choice isnt open even when i highlight the whole project

This post has been edited by heyoman1: 14 June 2010 - 04:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Why isnt this OpenGL program not working for me?

#2 Splatocaster   User is offline

  • D.I.C Head
  • member icon

Reputation: 51
  • View blog
  • Posts: 182
  • Joined: 22-December 09

Re: Why isnt this OpenGL program not working for me?

Posted 14 June 2010 - 04:38 PM

Did you link to OpenGL32.lib, GLu32.lib, and all other OpenGL static libraries?
Was This Post Helpful? 0
  • +
  • -

#3 heyoman1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: Why isnt this OpenGL program not working for me?

Posted 14 June 2010 - 06:03 PM

View PostSplatocaster, on 14 June 2010 - 03:38 PM, said:

Did you link to OpenGL32.lib, GLu32.lib, and all other OpenGL static libraries?

What does that even mean? :P
please explain how I may be able to do this
Was This Post Helpful? 0
  • +
  • -

#4 Aphex19   User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Why isnt this OpenGL program not working for me?

Posted 14 June 2010 - 06:38 PM

You need to tell Dev C++ where your functions are defined that you are calling, so you need to link the correct libraries. For a basic OpenGL program, these are libraries I link.

opengl32.lib glu32.lib glaux.lib odbc32.lib odbccp32.lib

If you haven't got these, you will need to download these first, they should be around the same place as your OpenGL header files in a folder called "libs" or something similer.

To link in Dev C++, I believe that you must add the libraries in
"project options->linker", but please don't take my word for it, I haven't got Dev C++ installed at the moment. By the way, why not download Visual C++ Express, registration is free, so much better.
Was This Post Helpful? 0
  • +
  • -

#5 heyoman1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: Why isnt this OpenGL program not working for me?

Posted 15 June 2010 - 04:51 PM

Now it's giving me this error
[Build Error] [Gl.exe] Error 1


Was This Post Helpful? 0
  • +
  • -

#6 heyoman1   User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: Why isnt this OpenGL program not working for me?

Posted 16 June 2010 - 01:50 PM

Please help
Was This Post Helpful? 0
  • +
  • -

#7 Munawwar   User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Why isnt this OpenGL program not working for me?

Posted 16 June 2010 - 02:34 PM

View Postheyoman1, on 16 June 2010 - 02:51 AM, said:

Now it's giving me this error
[Build Error] [Gl.exe] Error 1


List out what all steps did you do?

In general, to include any static library using GNU ld (for CodeBlocks and Dev-C++) of the form libXYZ.a you need to add -lXYZ to the linker options. (Same linker options to add multiple library files.). Keep in mind, that this is the same for any third party library.

In Dev-C++, Tools->Compiler Options or Project Options->linker
Tick the 'Add these commands to the linker command line' and add the required libraries in the text box below it.

In CodeBlocks, you can add a static library file by right-clicking project name->build options->Linker settings->Linker libraries, press the add button and add any library required for your project.

I am not sure which all libraries are needed for OpenGL, I think libglaux.a, libglu32.a, and libglut32.a. (I also see libglut.a and libgmon.a - but I am not sure whether they are needed).

So add -lglaux -lglu32 -lglut32 to the linker options.


[This note is for others who wants to link any 3rd party library: For libraries which are in not in the MinGW/lib directory you will also need to add your library directory into library search path.

For 3rd party libraries that uses dynamic linking (dll files), you may have to add the path to the dll, in the enviornment variables - like for wxWidgets in CodeBlocks.]

That's all about linking. Hopefully that will help you (and anyone else in future) clear the linking problems.

This post has been edited by Munawwar: 16 June 2010 - 03:07 PM

Was This Post Helpful? 0
  • +
  • -

#8 Munawwar   User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Why isnt this OpenGL program not working for me?

Posted 16 June 2010 - 03:10 PM

I just tried to link a lib file with MinGW as written here, but no it doesn't work.

It's better to follow this page

Edited my previous post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1