Thread: ceil mystery

  1. #1
    Registered User Drogin's Avatar
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    105

    ceil mystery

    Code:
    #include <math.h>
    #include <string.h>
    
    int main(void)  {
      double test = (double) strlen("TEST");
      double test2 =(double) ceil(test);
      return 0;
    }
    This gives me the following error:
    undefined reference to `ceil'

    This however, works:
    Code:
    #include <math.h>
    #include <string.h>
    
    int main(void)  {
      double test = (double) strlen("TEST");
      (double) ceil(test);
      return 0;
    }

    Why? What is going on? Oo

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Are you linking the math library?

    gcc -o foo foo.c -lm


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Drogin's Avatar
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    105
    Damn...no, I wasnt
    I knew there would be something basic I had forgotten to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird errors gcc : functions like floor(), ceil(), sqrt()
    By gemini_shooter in forum C Programming
    Replies: 2
    Last Post: 06-04-2005, 09:00 AM
  2. Constructors now allowed a return type: Mystery Error
    By wbeasl in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2004, 02:33 PM
  3. Mystery.
    By Nutshell in forum C Programming
    Replies: 1
    Last Post: 01-27-2002, 01:41 AM
  4. I need a function like ceil which returns an integer
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-20-2001, 10:16 AM
  5. The great mystery
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 39
    Last Post: 08-15-2001, 08:08 PM