Thread: #include<math.h>

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    29

    Unhappy #include<math.h>

    Hi,

    I am working in linux Redhat7.1, P3 system.

    Whenever I compile a program which has a math function, I use the command:

    cc filename.c -lm

    I have to do this inspite of including math.h

    The errors that were displayed when I didnot use -lm are as follows:::
    ***********************************************

    bash-2.04$ cc test.c
    /tmp/ccUQaDNH.o: In function `main':
    /tmp/ccUQaDNH.o(.text+0x1e): undefined reference to `sin'
    /tmp/ccUQaDNH.o(.text+0x4a): undefined reference to `sqrt'
    collect2: ld returned 1 exit status
    bash-2.04$ cc test.c -lm
    *---------------------------------------------

    What does this -lm signify and why should I give this.

    Ashesh

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    not familiar with your compiler but my best guess would be that the compiler switch lm loads the maths library.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    29
    In addition to math.h which other *.h files will need me to add switches like "-lm"

    ashesh

Popular pages Recent additions subscribe to a feed