undefined reference help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • none

    #1

    undefined reference help

    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 =----
  • Joe Estock

    #2
    Re: undefined reference help

    none wrote:[color=blue]
    > 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!
    >[/color]
    [snip newsfeeds.com appendage]

    [OT]
    link with -lmath
    [/OT]

    Joe

    Comment

    • Mark McIntyre

      #3
      Re: undefined reference help

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

      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 =----

      Comment

      • Keith Thompson

        #4
        Re: undefined reference help

        Joe Estock <jestock@NOSPAM nutextonline.co m> writes:[color=blue]
        > none wrote:[color=green]
        >> 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.[/color][/color]
        [...][color=blue]
        > [OT]
        > link with -lmath
        > [/OT][/color]

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

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <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.

        Comment

        • Martin Ambuhl

          #5
          Re: undefined reference help

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

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

          Comment

          • Joe Estock

            #6
            Re: undefined reference help

            Keith Thompson wrote:[color=blue]
            > Joe Estock <jestock@NOSPAM nutextonline.co m> writes:
            >[color=green]
            >>none wrote:
            >>[color=darkred]
            >>>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.[/color][/color]
            >
            > [...]
            >[color=green]
            >>[OT]
            >>link with -lmath
            >>[/OT][/color]
            >
            >
            > [OT]
            > -lm, not -lmath.
            > C FAQ 14.3 <http://www.eskimo.com/~scs/C-faq/faq.html>
            > [/OT]
            >[/color]

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

            Joe

            Comment

            • none

              #7
              Re: undefined reference help

              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:[color=blue]
              > none wrote:
              > [...]
              >[color=green]
              >> i get 'undefined reference to cos'. it happens with any function in
              >> math.h.
              >>
              >> what to do?[/color]
              >
              >
              > Here's how a civilized human being would do it: check the FAQ before
              > posting questions. The answer is there.[/color]

              ----== 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 =----

              Comment

              • Martin Ambuhl

                #8
                Re: undefined reference help

                none wrote:[color=blue]
                > 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[/color]

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

                Comment

                • Keith Thompson

                  #9
                  Re: undefined reference help

                  Martin Ambuhl <mambuhl@earthl ink.net> writes:[color=blue]
                  > none wrote:[color=green]
                  >> 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[/color]
                  >
                  > The biggest space wasters are the folks who post questions already
                  > answered in the FAQ. Buy a mirror.[/color]

                  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_Keit h) kst-u@mib.org <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.

                  Comment

                  • Mark McIntyre

                    #10
                    Re: undefined reference help

                    On Mon, 05 Dec 2005 16:03:13 -0500, in comp.lang.c , none <none@all>
                    wrote:
                    [color=blue]
                    >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[/color]

                    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 =----

                    Comment

                    • Joe Wright

                      #11
                      Re: undefined reference help

                      Mark McIntyre wrote:[color=blue]
                      > On Mon, 05 Dec 2005 16:03:13 -0500, in comp.lang.c , none <none@all>
                      > wrote:
                      >
                      >[color=green]
                      >>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[/color]
                      >
                      >
                      > You needed to search for "undefined" and then you'd have found several
                      > useful sections. Patience is important by the way.
                      >[/color]

                      Dear God. Please give me patience. Now!

                      --
                      Joe Wright
                      "Everything should be made as simple as possible, but not simpler."
                      --- Albert Einstein ---

                      Comment

                      • Richard Heathfield

                        #12
                        Re: undefined reference help

                        Joe Wright said:[color=blue]
                        > Mark McIntyre wrote:[color=green]
                        >> You needed to search for "undefined" and then you'd have found several
                        >> useful sections. Patience is important by the way.[/color]
                        >
                        > Dear God. Please give me patience. Now![/color]

                        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

                        email: rjh at above domain (but drop the www, obviously)

                        Comment

                        • Randy Howard

                          #13
                          Re: undefined reference help

                          Richard Heathfield wrote
                          (in article
                          <dn3357$4nb$1@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>):
                          [color=blue]
                          > Uh-oh. You know what happens when you ask God for more patience? He sends
                          > you more children.[/color]

                          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





                          Comment

                          • Richard Bos

                            #14
                            Re: undefined reference help

                            Richard Heathfield <invalid@invali d.invalid> wrote:
                            [color=blue]
                            > Joe Wright said:[color=green]
                            > > Mark McIntyre wrote:[color=darkred]
                            > >> You needed to search for "undefined" and then you'd have found several
                            > >> useful sections. Patience is important by the way.[/color]
                            > >
                            > > Dear God. Please give me patience. Now![/color]
                            >
                            > Uh-oh. You know what happens when you ask God for more patience? He sends
                            > you more children.[/color]

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

                            Richard

                            Comment

                            • Mark McIntyre

                              #15
                              Re: undefined reference help

                              On Tue, 6 Dec 2005 04:13:27 +0000 (UTC), in comp.lang.c , Richard
                              Heathfield <invalid@invali d.invalid> wrote:
                              [color=blue]
                              >Uh-oh. You know what happens when you ask God for more patience? He sends
                              >you more children.[/color]

                              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 =----

                              Comment

                              Working...