2010-11-15 38 views
2

我正在做一些用于linux的opengl实验。给出这些参数,我有以下函数可以绘制一个圆。我已经包括为什么这个小函数(在opengl中画一个圆)在c中编译?

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

然而,当我编译:

gcc fiver.c -o fiver -lglut 

我得到:

/usr/bin/ld: /tmp/ccGdx4hW.o: undefined reference to symbol '[email protected]@GLIBC_2.2.5' 
    /usr/bin/ld: note: '[email protected]@GLIBC_2.2.5' is defined in DSO /lib64/libm.so.6 so try 
    adding it to the linker command line 
    /lib64/libm.so.6: could not read symbols: Invalid operation 
    collect2: ld returned 1 exit status 

的功能如下:

void drawCircle (int xc, int yc, int rad) { 
// 
// draw a circle centered at (xc,yc) with radius rad 
// 
    glBegin(GL_LINE_LOOP); 
// 
    int angle; 
    for(angle = 0; angle < 365; angle = angle+5) { 
    double angle_radians = angle * (float)3.14159/(float)180; 
    float x = xc + rad * (float)cos(angle_radians); 
    float y = yc + rad * (float)sin(angle_radians); 
    glVertex3f(x,0,y); 
    } 

    glEnd(); 
} 

有谁知道什么是错误?

+3

它不是无法编译;它无法链接。 – 2010-11-15 20:19:22

+0

嗯,事后看来,这似乎是一个真正的问题:'/lib64/libm.so.6:无法读取符号:操作无效' - 但我不知道问题可能在那里......可能不匹配64/32库? – cdhowie 2010-11-15 20:22:24

+0

您可能还想研究绘制圆圈时可以使用的技巧。圆圈有很多对称性,您可以使用它来减少以(0,0) – nategoose 2010-11-15 22:34:47

回答

17

链接器找不到sin()函数的定义。您需要将您的应用程序与数学库链接。编译:

gcc fiver.c -o fiver -lglut -lm 
+0

为周围的圆圈调用trig函数的次数3倍!非常感谢! – dasen 2010-11-15 20:25:59

相关问题