Why do I get an undefined reference( to `glColor3f' ,for example) when I compile a program in c?

末鹿安然 提交于 2019-12-07 07:05:14

问题


I'm compiling an example program that uses opengl in ubuntu (linux). A short snippet of the code is the following:

 #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've installed all of the packages to develop 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 like this:

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 along the same line.

Does anyone know what I'm doing wrong?

Thanx in advance for any help.


回答1:


Try gcc -o main CG_ex4.c -lGL. The correct order of gcc parameters is important.




回答2:


Try including GL/gl.h as well as glut. Kind of weird though, since glut actually includes both gl.h and glu.h.



来源:https://stackoverflow.com/questions/4179079/why-do-i-get-an-undefined-reference-to-glcolor3f-for-example-when-i-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!