Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   undefined reference to `trunc' (http://www.velocityreviews.com/forums/t435944-undefined-reference-to-trunc.html)

Giulio 11-24-2004 06:22 PM

undefined reference to `trunc'
 
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
------------------------------------------------

S.Tobias 11-24-2004 06:36 PM

Re: undefined reference to `trunc'
 
Giulio <frank.zappalEVA@email.it.invalid> 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 siXtY@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`

=?ISO-8859-1?Q?Bj=F8rn_Augestad?= 11-24-2004 06:37 PM

Re: undefined reference to `trunc'
 
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


Keith Thompson 11-24-2004 08:18 PM

Re: undefined reference to `trunc'
 
Giulio <frank.zappalEVA@email.it.invalid> 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) 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.

jacob navia 11-24-2004 09:25 PM

Re: undefined reference to `trunc'
 
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

Jack Klein 11-25-2004 08:51 PM

Re: undefined reference to `trunc'
 
On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
<jacob@jacob.remcomp.fr> 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/~a...FAQ-acllc.html

Jens.Toerring@physik.fu-berlin.de 11-26-2004 12:23 AM

Re: undefined reference to `trunc'
 
Jack Klein <jackklein@spamcop.net> wrote:
> On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
> <jacob@jacob.remcomp.fr> 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 ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de

Dave Vandervies 11-26-2004 01:06 AM

Re: undefined reference to `trunc'
 
In article <30nbbnF2uuj0pU2@uni-berlin.de>,
<Jens.Toerring@physik.fu-berlin.de> wrote:
>Jack Klein <jackklein@spamcop.net> 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 dj3vande@csclub.uwaterloo.ca

Right now? Either. Just fly out on your pig and buy one.
--Nick Maclaren in comp.arch


All times are GMT. The time now is 02:09 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.