naseeam
asked on
Why sin function doesn't work?
I'm using my personal linux laptop that I purchased a year ago to write following c program in vim editor: The operating system is Ubuntu.
/tmp/ccDTU7GW.o: In function `main':
first.c:(.text+0x39): undefined reference to `sin'
collect2: error: ld returned 1 exit status
In /usr/include folder, there is math.h but I didn't find any sin function prototypes in this file.
#include <stdio.h>
#include <math.h>
int main( )
{
double x;
float y;
x = 45.0; /* 45 degrees */
x *= (3.141593 / 180.0);
y = sin(x);
printf ("The result is: %f\n", y);
return 0;
}
When I compile, I get the following error:/tmp/ccDTU7GW.o: In function `main':
first.c:(.text+0x39): undefined reference to `sin'
collect2: error: ld returned 1 exit status
In /usr/include folder, there is math.h but I didn't find any sin function prototypes in this file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@noci
Thank you so much for providing another great solution. I didn't see it until now.
Thank you so much for providing another great solution. I didn't see it until now.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Man sin starts with:
Open in new window
Which tells you that you need the include file math.h and what library to link with.For most functions such a page exists. For those that don't have it the provider of the library will have some form of documentation.
in general if a library has been provided as: libxyz.so then you can specify it on the link command with -lxyz (gcc compiler with linkage included will accept those and pass them on to the linker (ld)