undefined reference help

Discussion in 'C Programming' started by none, Dec 4, 2005.

  1. none

    none Guest

    i have:

    #include <math.h>

    int main (void)
    {
    double i = 0.0;
    double v = 0.0;

    i = cos(v);

    return 0;
    }


    i get 'undefined reference to cos'. it happens with any
    function in math.h.

    what to do?

    btw using rh 8.0 3.2-7 gcc version 3.2

    please & thanks!

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    none, Dec 4, 2005
    #1
    1. Advertising

  2. none

    Joe Estock Guest

    none wrote:
    > i have:
    >
    > #include <math.h>
    >
    > int main (void)
    > {
    > double i = 0.0;
    > double v = 0.0;
    >
    > i = cos(v);
    >
    > return 0;
    > }
    >
    >
    > i get 'undefined reference to cos'. it happens with any function in math.h.
    >
    > what to do?
    >
    > btw using rh 8.0 3.2-7 gcc version 3.2
    >
    > please & thanks!
    >

    [snip newsfeeds.com appendage]

    [OT]
    link with -lmath
    [/OT]

    Joe
     
    Joe Estock, Dec 4, 2005
    #2
    1. Advertising

  3. On Sun, 04 Dec 2005 18:49:39 -0500, in comp.lang.c , none <none@all>
    wrote:
    >
    >i get 'undefined reference to cos'. it happens with any
    >function in math.h.


    This is a FAQ. Please read it.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Dec 5, 2005
    #3
  4. Joe Estock <> writes:
    > none wrote:
    >> i have:
    >> #include <math.h>
    >> int main (void)
    >> {
    >> double i = 0.0;
    >> double v = 0.0;
    >> i = cos(v);
    >> return 0;
    >> }
    >> i get 'undefined reference to cos'. it happens with any function in
    >> math.h.

    [...]
    > [OT]
    > link with -lmath
    > [/OT]


    [OT]
    -lm, not -lmath.
    C FAQ 14.3 <http://www.eskimo.com/~scs/C-faq/faq.html>
    [/OT]

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Dec 5, 2005
    #4
  5. none wrote:
    [...]
    > i get 'undefined reference to cos'. it happens with any function in math.h.
    >
    > what to do?


    Here's how a civilized human being would do it: check the FAQ before
    posting questions. The answer is there.
     
    Martin Ambuhl, Dec 5, 2005
    #5
  6. none

    Joe Estock Guest

    Keith Thompson wrote:
    > Joe Estock <> writes:
    >
    >>none wrote:
    >>
    >>>i have:
    >>>#include <math.h>
    >>>int main (void)
    >>>{
    >>> double i = 0.0;
    >>> double v = 0.0;
    >>> i = cos(v);
    >>> return 0;
    >>>}
    >>>i get 'undefined reference to cos'. it happens with any function in
    >>>math.h.

    >
    > [...]
    >
    >>[OT]
    >>link with -lmath
    >>[/OT]

    >
    >
    > [OT]
    > -lm, not -lmath.
    > C FAQ 14.3 <http://www.eskimo.com/~scs/C-faq/faq.html>
    > [/OT]
    >


    Thanks for the catch Keith. I've been up far too long and I'm running
    low on coffee.

    Joe
     
    Joe Estock, Dec 5, 2005
    #6
  7. none

    none Guest

    i can take one, but i'll answer this one, i did check the
    faq. i clicked on 'all questions' & searched for 'undefined
    reference'. i didn't get any hits. thanks to all esp. joe
    who got me on the right track. so can't we all get along &
    stop wasting space here? ty

    Martin Ambuhl wrote:
    > none wrote:
    > [...]
    >
    >> i get 'undefined reference to cos'. it happens with any function in
    >> math.h.
    >>
    >> what to do?

    >
    >
    > Here's how a civilized human being would do it: check the FAQ before
    > posting questions. The answer is there.


    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    none, Dec 5, 2005
    #7
  8. none wrote:
    > i can take one, but i'll answer this one, i did check the faq. i clicked
    > on 'all questions' & searched for 'undefined reference'. i didn't get
    > any hits. thanks to all esp. joe who got me on the right track. so
    > can't we all get along & stop wasting space here? ty


    The biggest space wasters are the folks who post questions already
    answered in the FAQ. Buy a mirror.
     
    Martin Ambuhl, Dec 5, 2005
    #8
  9. Martin Ambuhl <> writes:
    > none wrote:
    >> i can take one, but i'll answer this one, i did check the faq. i
    >> clicked on 'all questions' & searched for 'undefined reference'. i
    >> didn't get any hits. thanks to all esp. joe who got me on the right
    >> track. so can't we all get along & stop wasting space here? ty

    >
    > The biggest space wasters are the folks who post questions already
    > answered in the FAQ. Buy a mirror.


    In the OP's defense, that particular FAQ can be difficult to find if
    you don't already know what you're looking for. The question is

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

    A search for "undefined" or "math.h" would have found it, but it's
    understandable that someone could miss it. (It usually takes me a
    couple of tries to find that one myself, and I already know the
    answer.)

    I suggest that the only response needed for the original question was

    C FAQ 14.3 <http://www.eskimo.com/~scs/C-faq/faq.html>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Dec 5, 2005
    #9
  10. On Mon, 05 Dec 2005 16:03:13 -0500, in comp.lang.c , none <none@all>
    wrote:

    >i can take one, but i'll answer this one, i did check the
    >faq. i clicked on 'all questions' & searched for 'undefined
    >reference'. i didn't get any hits


    You needed to search for "undefined" and then you'd have found several
    useful sections. Patience is important by the way.

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Dec 5, 2005
    #10
  11. none

    Joe Wright Guest

    Mark McIntyre wrote:
    > On Mon, 05 Dec 2005 16:03:13 -0500, in comp.lang.c , none <none@all>
    > wrote:
    >
    >
    >>i can take one, but i'll answer this one, i did check the
    >>faq. i clicked on 'all questions' & searched for 'undefined
    >>reference'. i didn't get any hits

    >
    >
    > You needed to search for "undefined" and then you'd have found several
    > useful sections. Patience is important by the way.
    >


    Dear God. Please give me patience. Now!

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
     
    Joe Wright, Dec 6, 2005
    #11
  12. Joe Wright said:
    > Mark McIntyre wrote:
    >> You needed to search for "undefined" and then you'd have found several
    >> useful sections. Patience is important by the way.

    >
    > Dear God. Please give me patience. Now!


    Uh-oh. You know what happens when you ask God for more patience? He sends
    you more children.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Dec 6, 2005
    #12
  13. none

    Randy Howard Guest

    Richard Heathfield wrote
    (in article
    <dn3357$4nb$-infra.bt.com>):

    > Uh-oh. You know what happens when you ask God for more patience? He sends
    > you more children.


    D O E S N O T C O M P U T E


    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
     
    Randy Howard, Dec 6, 2005
    #13
  14. none

    Richard Bos Guest

    Richard Heathfield <> wrote:

    > Joe Wright said:
    > > Mark McIntyre wrote:
    > >> You needed to search for "undefined" and then you'd have found several
    > >> useful sections. Patience is important by the way.

    > >
    > > Dear God. Please give me patience. Now!

    >
    > Uh-oh. You know what happens when you ask God for more patience? He sends
    > you more children.


    That's a good thing, surely? Unless you're out of Andalouse.

    Richard
     
    Richard Bos, Dec 6, 2005
    #14
  15. On Tue, 6 Dec 2005 04:13:27 +0000 (UTC), in comp.lang.c , Richard
    Heathfield <> wrote:

    >Uh-oh. You know what happens when you ask God for more patience? He sends
    >you more children.


    You mean, trial by ordeal...

    anyway, to get children you need to fork, and thats offtopic here....

    gd&r

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Dec 6, 2005
    #15
    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. Quansheng Liang
    Replies:
    2
    Views:
    565
    Quansheng Liang
    May 25, 2004
  2. Mantorok Redgormor
    Replies:
    70
    Views:
    1,763
    Dan Pop
    Feb 17, 2004
  3. boyphp
    Replies:
    2
    Views:
    299
    Victor Bazarov
    May 2, 2007
  4. VK
    Replies:
    45
    Views:
    602
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    373
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page