Reputation: 529
Why does the following program compile with gcc, ...
#include<stdio.h>
#include<math.h>
void foo(double x) {
printf("%f", sin(2));
}
int main() {
foo(1);
}
... while this other program doesn't?
#include<stdio.h>
#include<math.h>
void foo(double x) {
printf("%f", sin(x));
}
int main() {
foo(1);
}
It gives the following error message:
/tmp/ccVT7jlb.o: nella funzione "foo":
fun.c:(.text+0x1b): riferimento non definito a "sin"
collect2: error: ld returned 1 exit status*
Upvotes: 1
Views: 44
Reputation: 53016
You need to link to libm.so
like this
gcc -Wall -Wextra -Werror source.c -o executable -lm
see the -lm
Upvotes: 2