Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > undefined reference to `trunc'

Reply
Thread Tools

undefined reference to `trunc'

 
 
Giulio
Guest
Posts: n/a
 
      11-24-2004
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
------------------------------------------------
 
Reply With Quote
 
 
 
 
S.Tobias
Guest
Posts: n/a
 
      11-24-2004
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`
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Bj=F8rn_Augestad?=
Guest
Posts: n/a
 
      11-24-2004
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

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-24-2004
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) kst- <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.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      11-24-2004
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
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      11-25-2004
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/~a...FAQ-acllc.html
 
Reply With Quote
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      11-26-2004
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 ___
\__________________________ http://www.toerring.de
 
Reply With Quote
 
Dave Vandervies
Guest
Posts: n/a
 
      11-26-2004
In article <>,
<> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typeof x == 'undefined' or x == undefined? -Lost Javascript 13 01-31-2007 12:04 AM
undefined vs. undefined (was: new Array() vs []) VK Javascript 45 09-12-2006 05:26 PM
'Undefined' Client-Side Object Reference Felipe ASP .Net 3 07-16-2004 04:01 AM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
Error: 'undefined reference' in g++ but gcc succeeded Lu C++ 1 07-10-2003 12:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57