Click here to Skip to main content
15,886,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code:
C
#include<stdio.h>
#include<math.h>
int main() {

  double R;      
  double omega;   
  double x, y,t;
  R=6.2;
  omega=0.1;
  t=0;
  x=R*cos(omega*t);
  y=R*sin(omega*t);
  printf("t=%lf\n x=%lf\n y=%lf\n",t, x, y);
}




When compiling it with gcc test.c I get the following error, and I can't work out why:
/usr/bin/ld: /tmp/ccf5Bi7l.o: in function `main':
circle.c:(.text+0x5e): undefined reference to `cos'
/usr/bin/ld: circle.c:(.text+0x7b): undefined reference to `sin'
collect2: error: ld returned 1 exit status


What I have tried:

Can someone help me with this problem?
Posted
Updated 28-Dec-20 20:05pm
v2

1 solution

You must link with the math library.
gcc test.c -lm
 
Share this answer
 
Comments
CPallini 29-Dec-20 2:05am    
5.
Shao Voon Wong 29-Dec-20 2:22am    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900