簡體   English   中英

為什么這個小函數(在opengl中畫一個圓圈)不會在c中編譯?

[英]Why won't this small function(drawing a circle in opengl) compile in c?

我正在用linux中的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM