compiler unable to find defn. of sin()

Discussion in 'C Programming' started by sudip, Jun 24, 2005.

  1. sudip

    sudip Guest

    Dear All,
    I'm having a nightmare compiling a small simple program on a Linux
    Fedora core 2 platform...the program goes like this...

    in file mathtest.c

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

    int main(void)
    {
    printf("%s%d\n","The value of sin(3) is: ", sin(3));
    return 0;
    }

    I'm compiling the above program by issuing the following command on
    bash shell...

    gcc -Wall -o mathtest mathtest.c

    the compiler is throwing the following error

    in function 'main':
    :undefined reference to 'sin'

    ....and stops the compilation process..
    I'm stuck up, and can't figure out the error..plz help
    sudip, Jun 24, 2005
    #1
    1. Advertising

  2. sudip

    Artie Gold Guest

    sudip wrote:
    > Dear All,
    > I'm having a nightmare compiling a small simple program on a Linux
    > Fedora core 2 platform...the program goes like this...
    >
    > in file mathtest.c
    >
    > #include <math.h>
    > #include <stdio.h>
    >
    > int main(void)
    > {
    > printf("%s%d\n","The value of sin(3) is: ", sin(3));
    > return 0;
    > }
    >
    > I'm compiling the above program by issuing the following command on
    > bash shell...
    >
    > gcc -Wall -o mathtest mathtest.c
    >
    > the compiler is throwing the following error
    >
    > in function 'main':
    > :undefined reference to 'sin'
    >
    > ...and stops the compilation process..
    > I'm stuck up, and can't figure out the error..plz help
    >

    This is a FAQ. Find it. Read it. It's not that hard. (And doing so will
    serve you *very* well in the long run.)

    HTH,
    --ag
    --
    Artie Gold -- Austin, Texas
    http://it-matters.blogspot.com (new post 12/5)
    http://www.cafepress.com/goldsays
    Artie Gold, Jun 24, 2005
    #2
    1. Advertising

  3. sudip wrote:

    > the compiler is throwing the following error
    >
    > in function 'main':
    > :undefined reference to 'sin'
    >
    > ...and stops the compilation process..
    > I'm stuck up, and can't figure out the error..plz help
    >


    The best help (teach a man to fish): check the FAQ before posting.

    The inferior help (give you the fish): what you'll find there. Does it
    look familiar?
    <http://www.eskimo.com/~scs/C-faq/q14.3.html>
    Question 14.3

    I'm trying to do some simple trig, and I am #including <math.h>, but I
    keep getting ``undefined: sin'' compilation errors.

    Make sure you're actually linking with the math library. For instance,
    under Unix, you usually need to use the -lm option, at the end of the
    command line, when compiling/linking. See also questions 13.25 and 13.26.
    Martin Ambuhl, Jun 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    448
    tom_usenet
    Sep 9, 2003
  2. Alexander Stippler

    why do I need ::sin, not std::sin?

    Alexander Stippler, Jun 4, 2004, in forum: C++
    Replies:
    14
    Views:
    830
    Pete Becker
    Jun 5, 2004
  3. Replies:
    1
    Views:
    722
  4. gopal
    Replies:
    4
    Views:
    401
    gopal
    Jun 17, 2006
  5. mindswitness

    Fn Defn Style

    mindswitness, Dec 12, 2009, in forum: C Programming
    Replies:
    38
    Views:
    818
    Flash Gordon
    Dec 16, 2009
Loading...

Share This Page