undefined reference to `trunc'

Discussion in 'C Programming' started by Giulio, Nov 24, 2004.

  1. Giulio

    Giulio Guest

    I can't understand where is the problem:
    this is the file I would like to compile
    ------------------------
    #include <math.h>
    #include <stdlib.h>

    int main (){
    int c = trunc(17.5);
    return c;
    }
    --------------------------

    with this command:
    --------------------
    gcc -o prova prova.c
    ----------------------------
    and this is the error the compiler gives me.

    -----------------------------
    /tmp/cc0ZzTZJ.o: In function `main':
    /tmp/cc0ZzTZJ.o(.text+0x32): undefined reference to `trunc'
    collect2: ld returned 1 exit status
    ------------------------------------------------
     
    Giulio, Nov 24, 2004
    #1
    1. Advertising

  2. Giulio

    S.Tobias Guest

    Giulio <> wrote:
    > this is the file I would like to compile
    > ------------------------
    > #include <math.h>

    [snip]
    > --------------------------


    > with this command:
    > --------------------
    > gcc -o prova prova.c


    gcc -o prova prova.c -lm

    man gcc

    > ----------------------------
    > and this is the error the compiler gives me.


    strictly: it's from the linker

    > -----------------------------
    > /tmp/cc0ZzTZJ.o: In function `main':
    > /tmp/cc0ZzTZJ.o(.text+0x32): undefined reference to `trunc'
    > collect2: ld returned 1 exit status

    ^^
    > ------------------------------------------------


    --
    Stan Tobias
    mailx `echo LID | sed s/[[:upper:]]//g`
     
    S.Tobias, Nov 24, 2004
    #2
    1. Advertising

  3. Giulio wrote:

    > I can't understand where is the problem:
    > this is the file I would like to compile
    > ------------------------
    > #include <math.h>
    > #include <stdlib.h>
    >
    > int main (){
    > int c = trunc(17.5);
    > return c;
    > }
    > --------------------------
    >
    > with this command:
    > --------------------
    > gcc -o prova prova.c


    Try gcc -o prova prova.c -lm
    where m is for the math library and the l is the letter ell.

    HTH
    Bjørn
     
    =?ISO-8859-1?Q?Bj=F8rn_Augestad?=, Nov 24, 2004
    #3
  4. Giulio <> writes:
    [...]
    > -----------------------------
    > /tmp/cc0ZzTZJ.o: In function `main':
    > /tmp/cc0ZzTZJ.o(.text+0x32): undefined reference to `trunc'
    > collect2: ld returned 1 exit status
    > ------------------------------------------------


    This is question 14.3 in the C FAQ,
    <http://www.eskimo.com/~scs/C-faq/top.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, Nov 24, 2004
    #4
  5. Giulio

    jacob navia Guest

    Bjørn Augestad wrote:

    > Giulio wrote:
    >
    >> I can't understand where is the problem:
    >> this is the file I would like to compile
    >> ------------------------
    >> #include <math.h>
    >> #include <stdlib.h>
    >>
    >> int main (){
    >> int c = trunc(17.5);
    >> return c;
    >> }
    >> --------------------------
    >>
    >> with this command:
    >> --------------------
    >> gcc -o prova prova.c

    >
    >
    > Try gcc -o prova prova.c -lm
    > where m is for the math library and the l is the letter ell.
    >
    > HTH
    > Bjørn
    >


    Ahhh couldn't gcc include the math lib by default?????

    The few microseconds that this would cost in modern machines
    would be *really* justified by the easier user interface.

    This is a relic of the old days when machines were so slow that
    including or not the math lib made a difference in link time.

    Today, this is completely obsolete.

    jacob
     
    jacob navia, Nov 24, 2004
    #5
  6. Giulio

    Jack Klein Guest

    On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
    <> wrote in comp.lang.c:

    > Bjørn Augestad wrote:
    >
    > > Giulio wrote:
    > >
    > >> I can't understand where is the problem:
    > >> this is the file I would like to compile
    > >> ------------------------
    > >> #include <math.h>
    > >> #include <stdlib.h>
    > >>
    > >> int main (){
    > >> int c = trunc(17.5);
    > >> return c;
    > >> }
    > >> --------------------------
    > >>
    > >> with this command:
    > >> --------------------
    > >> gcc -o prova prova.c

    > >
    > >
    > > Try gcc -o prova prova.c -lm
    > > where m is for the math library and the l is the letter ell.
    > >
    > > HTH
    > > Bjørn
    > >

    >
    > Ahhh couldn't gcc include the math lib by default?????
    >
    > The few microseconds that this would cost in modern machines
    > would be *really* justified by the easier user interface.
    >
    > This is a relic of the old days when machines were so slow that
    > including or not the math lib made a difference in link time.
    >
    > Today, this is completely obsolete.
    >
    > jacob


    Yes, of course, but this comes from the *NIX world, where the gurus
    will NEVER give up their advantage over newbies. They want the
    newcomers to come groveling to their betters.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Nov 25, 2004
    #6
  7. Giulio

    -berlin.de Guest

    Jack Klein <> wrote:
    > On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
    > <> wrote in comp.lang.c:
    >> >> with this command:
    >> >> --------------------
    >> >> gcc -o prova prova.c
    >> >
    >> >
    >> > Try gcc -o prova prova.c -lm
    >> > where m is for the math library and the l is the letter ell.
    >> >
    >> > HTH
    >> > Bjørn
    >> >

    >>
    >> Ahhh couldn't gcc include the math lib by default?????
    >>
    >> The few microseconds that this would cost in modern machines
    >> would be *really* justified by the easier user interface.
    >>
    >> This is a relic of the old days when machines were so slow that
    >> including or not the math lib made a difference in link time.
    >>
    >> Today, this is completely obsolete.
    >>
    >> jacob


    > Yes, of course, but this comes from the *NIX world, where the gurus
    > will NEVER give up their advantage over newbies. They want the
    > newcomers to come groveling to their betters.


    Aren't you a bit harsh here? I guess it got more to do with the fact
    that there are that many different implementations of UNIX that it
    takes a lot longer for such changes to get adopted by everyone. That's
    quite a bit more difficult than in a world where you have a single
    company that can tell everyone how to do things and rewrite every-
    thing you have because they decided to do things differently without
    having to get a consensus.
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
     
    -berlin.de, Nov 26, 2004
    #7
  8. In article <>,
    <-berlin.de> wrote:
    >Jack Klein <> wrote:


    >> Yes, of course, but this comes from the *NIX world, where the gurus
    >> will NEVER give up their advantage over newbies. They want the
    >> newcomers to come groveling to their betters.

    >
    >Aren't you a bit harsh here? I guess it got more to do with the fact
    >that there are that many different implementations of UNIX that it
    >takes a lot longer for such changes to get adopted by everyone. That's
    >quite a bit more difficult than in a world where you have a single
    >company that can tell everyone how to do things and rewrite every-
    >thing you have because they decided to do things differently without
    >having to get a consensus.


    Jack may be being too harsh, but you're being too generous, so it
    balances out.

    Unix culture has a "It works this way, it's worked this way for a long
    time, why waste energy changing it?" attitude that assumes easy access
    to the corresponding oral tradition and causes problems without that.

    "You know that now, so we still don't need to change it" tends to work a
    lot better when everybody can go visit the guru down the hall than when
    people are trying to learn it on their own.


    dave

    --
    Dave Vandervies

    Right now? Either. Just fly out on your pig and buy one.
    --Nick Maclaren in comp.arch
     
    Dave Vandervies, Nov 26, 2004
    #8
    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. arti

    trunc in verilog

    arti, May 10, 2006, in forum: VHDL
    Replies:
    0
    Views:
    582
  2. Mantorok Redgormor
    Replies:
    70
    Views:
    1,764
    Dan Pop
    Feb 17, 2004
  3. =?Utf-8?B?RGF2ZQ==?=
    Replies:
    2
    Views:
    15,998
    Alexey Smirnov
    Jul 15, 2007
  4. aryan

    ios::trunc vs unlink

    aryan, Jun 16, 2008, in forum: C++
    Replies:
    3
    Views:
    766
    James Kanze
    Jun 17, 2008
  5. Hicham Mouline
    Replies:
    2
    Views:
    778
    Keith Thompson
    Apr 23, 2010
Loading...

Share This Page