2010-11-15 16 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

相關問題