I am using the Opengl lib, but in the compilation gcc is returned indefinite reference, could anyone help?

Asked

Viewed 176 times

0

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

void reshape(int w, int h) {
glViewport(0, 0, w, h); /* Establish viewing area to cover entire 
window. */
glMatrixMode(GL_PROJECTION); /* Start modifying the projection matrix. 
*/
glLoadIdentity(); /* Reset project matrix. */
glOrtho(0, w, 0, h, -1, 1); /* Map abstract coords directly to window 
coords. */
glScalef(1, -1, 1); /* Invert Y axis so increasing Y goes down. */
glTranslatef(0, -h, 0); /* Shift origin up to upper-left corner. */
}

void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 1.0); /* blue */
glVertex2i(0, 0);
glColor3f(0.0, 1.0, 0.0); /* green */
glVertex2i(200, 200);
glColor3f(1.0, 0.0, 0.0); /* red */
glVertex2i(20, 200);
glEnd();
glFlush(); /* Single buffered, so needs a flush. */
}

int main(int argc, char **argv) {
glutInit(&argc, argv);
glutCreateWindow("single triangle");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0; [![referencia indefinida][1]][1]
}
  • Linkage error, you did not put through the build flags -l and -L where to find the libraries. In this specific case the code does not help much, what would help would be the build command line

  • gcc -lglut -lGLU -lGL open2.c -o open2.exe this is the command I use in the terminal to compile

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.