I noticed that when I use sin
inside function the compiler don't recognize it, here is an example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
float sinus(float a){
return sin(a);}
int main(int argc, char **argv)
{
double a = sinus(2);
printf("%f \n", sin(2));
printf("%f", a);
return 0;
}
If I use it directly in main it works fine, but inside a user defined function it gives me this error undefined reference to sin
.
For compiling I use gcc -Wall -lm -lc -lgcc -o "%e" "%f"
.
References to libraries typically go to the end of the command line, in particular after the sources have been specified:
(specifing the C lib is not necessary, it is linked implicilty)
From the documentation: