Using math library problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amiralis
    New Member
    • Sep 2012
    • 1

    Using math library problem

    Hi all,

    I include <math.h> to use functions such as "floor()". and also I use -lm to link to math library like the following:

    Code:
    all: setitimer-helper squish-pty squish-unix
    
    CC = gcc
    CFLAGS = -Wall -W
    LDFLAGS = -lm
    setitimer-helper: setitimer-helper.o
    squish-pty: squish-pty.o
    squish-unix: squish-unix.o
    
    clean: 
        rm -f *.o setitimer-helper squish-pty squish-unix
    But still I receive an error which says: "undefined reference to 'floor'"

    What would be the problem?

    Thanks in advance,
    Last edited by zmbd; Sep 15 '12, 06:27 AM. Reason: placed code tags...
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    An undefined reference is usually referrinf to something that has not been declared.

    Have you declared floor() as a function before calling it?

    Comment

    • nextstep
      New Member
      • Aug 2012
      • 14

      #3
      I think floor() is a function of math.h lib therefore no need to define it

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Weaknessforcats is correct, you are missing a reference to the function in order for this error to occur.

        I don't see in your posted code where you have the include for the math.h library, nor do I see a proper sub-reference/compile-time linker to the math library. Also missing is the context for the call to the floor function.

        You might take a look at:

        Comment

        Working...