Undefined reference to `pow' and `floor'
You need to compile with the link flag -lm
, like this:
gcc fib.c -lm -o fibo
This will tell gcc to link your code against the math lib. Just be sure to put the flag after the objects you want to link.
Add -lm to your link options, since pow() and floor() are part of the math library:
gcc fib.c -o fibo -lm
For the benefit of anyone reading this later, you need to link against it as Fred said:
gcc fib.c -lm -o fibo
One good way to find out what library you need to link is by checking the man page if one exists. For example, man pow
and man floor
will both tell you:
Link with -lm
.
An explanation for linking math library in C programming - Linking in C