0

I am trying to find the the ceil of a variable which was been assigned a value but when I pass the function ceil("variable name") it throws an error.

#include <stdio.h>
#include <math.h>

int main()
{
   double num = 8.33;
   int result;

   result = ceil(num);
   printf("Ceiling integer of %.2f = %d", num, result);

   return 0;
}

And the error which I am gettin is--

/usr/bin/ld: /tmp/ccG3j9iB.o: in function `main':
maximumRebounding.c:(.text+0x1f): undefined reference to `ceil'
collect2: error: ld returned 1 exit status
  • 1
    The linker needs `-lm`. Please see [Why Am I Getting Link Errors When Calling Function in Math.h?](https://stackoverflow.com/questions/103407/why-am-i-getting-link-errors-when-calling-function-in-math-h) – Weather Vane Aug 12 '23 at 09:17
  • This message indicates that the compiler has decided that you need more programming exercises. You need to implement it yourself – 0___________ Aug 12 '23 at 11:00

1 Answers1

0

With the developer tools you are using, you must include -lm on the command that builds the executable file to tell the linker to use the math library. Put it on the command after object modules and libraries that use routines from the math library.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312