我正在用 c for linux 中的 opengl 做一些实验。我有以下函数,可以根据这些参数绘制一个圆。我已经包括了
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
但是当我编译时:
gcc fiver.c -o fiver -lglut
I get:
/usr/bin/ld: /tmp/ccGdx4hW.o: undefined reference to symbol 'sin@@GLIBC_2.2.5'
/usr/bin/ld: note: 'sin@@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();
}
有谁知道出了什么问题吗?
链接器找不到 sin() 函数的定义。您需要将您的应用程序链接到数学库。编译:
gcc fiver.c -o fiver -lglut -lm
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)