P
P
Pinkman2020-05-09 15:16:02
C++ / C#
Pinkman, 2020-05-09 15:16:02

Why can't it find the function?

Hello! Faced such a problem: At the compilation stage, the compiler gives an error message (compiled with the following flags: gcc demo.c -lglut -Werror -Wextra -Wall -o program):

/usr/bin/ld: /tmp/ccic0NXk.o : undefined reference to symbol 'glVertex3f'
/usr/bin/ld: /lib/x86_64-linux-gnu/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit


status So:

#include <GL/glut.h>

void renderScene(void) {

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glBegin(GL_TRIANGLES);
    glVertex3f(-0.5,-0.5,0.0);
    glVertex3f(0.0,0.5,0.0);
    glVertex3f(0.5,-0.5,0.0);
  glEnd();

  glutSwapBuffers();
}

int main(int argc, char **argv) {

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  glutInitWindowPosition(100,100);
  glutInitWindowSize(400,400);
  glutCreateWindow("Demo window");

   glutDisplayFunc(renderScene);

  glutMainLoop();

  return 1;
}

If I remove the function with vertices, it compiles without errors and runs.
VS Code included auto-completion for all functions (I guess that means they are declared in the header)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pinkman, 2020-05-09
@famousman204

I found a solution, the lesson did not indicate that you need to pick up one more lib.
In general, you need to run it with the -lGL flag.
You need to compile it like this: gcc demo.c -lglut -lGL -Wall -Wextra -Werror -o program

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question