math - Why won't this small function(drawing a circle in opengl) compile in c? -


i'm doing experiments opengl in c linux. i've got following function draw circle given parameters. i've included

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

however when compile:

gcc fiver.c -o fiver -lglut 

i get:

   /usr/bin/ld: /tmp/ccgdx4hw.o: undefined reference symbol 'sin@@glibc_2.2.5'    /usr/bin/ld: note: 'sin@@glibc_2.2.5' defined in dso /lib64/libm.so.6 try      adding linker command line   /lib64/libm.so.6: not read symbols: invalid operation    collect2: ld returned 1 exit status 

the function following:

void drawcircle (int xc, int yc, int rad) { // // draw circle centered @ (xc,yc) 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 know what's wrong?

the linker cannot find definition of sin() function. need link application against math library. compile with:

gcc fiver.c -o fiver -lglut -lm 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -