Why can I get an undefined link (e.g. `glColor3f ') when I compile a program in c?

I am compiling an example program that uses opengl in ubuntu (linux). The short code snippet is as follows:

 #include <stdlib.h> 

 #include <GL/glut.h>


 void createBox( GLfloat centroX, GLfloat centroY,
                       GLfloat corR, GLfloat corG, GLfloat corB )
 {
    /* Cor  */

    glColor3f( corR, corG, corB );

I installed all development packages in opengl (in ubuntu), namely:

freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa
libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev

I compile the example as follows:

gcc -lGL   CG_ex04.c -o main

and I get the following

/tmp/ccDWmJDZ.o: In function `createBox':
CG_ex04.c:(.text+0x31): undefined reference to `glColor3f'

and other errors on the same line.

Does anyone know what I'm doing wrong?

Thanx for any help.

+3
source share
2 answers

Give it a try gcc -o main CG_ex4.c -lGL. The correct order of gcc parameters is important.

+7
source

GL/gl.h, . - , , gl.h, glu.h.

0

Source: https://habr.com/ru/post/1774812/


All Articles