Why does the following program compile with , ... 编译,...
#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*
You need to link to libm.so
like this
gcc -Wall -Wextra -Werror source.c -o executable -lm
see the -lm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.