gpt4 book ai didi

c - 为什么这个小函数(在opengl中画一个圆圈)不能用c编译?

转载 作者:行者123 更新时间:2023-12-01 15:07:24 26 4
gpt4 key购买 nike

我正在为 linux 在 c 中使用 opengl 做一些实验。我有以下函数可以根据这些参数绘制一个圆。我已经包含了

 #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 '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

关于c - 为什么这个小函数(在opengl中画一个圆圈)不能用c编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4188409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com