本文介绍了为什么不将这个小功能(绘制在OpenGL一个圆圈)编译C吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一些实验用OpenGL在C对于Linux。我有下面的函数,将画中给出的参数的循环。我已经包括

I'm doing some experiments with opengl in c for linux. I've got the following function that would draw a circle given those parameters. I've included

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

然而,当我编译:

However when I compile:

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();
}

有谁知道什么是错的?

Does anyone know what's wrong?

推荐答案

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

The linker cannot find the definition of sin() function. You need to link your application against the math library. Compile with:

gcc fiver.c -o fiver -lglut -lm

这篇关于为什么不将这个小功能(绘制在OpenGL一个圆圈)编译C吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 22:17