473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
------------------------------------------------
Nov 14 '05 #1
7 9151
Giulio <fr*************@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 si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #2
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

Nov 14 '05 #3
Giulio <fr*************@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) ks***@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.
Nov 14 '05 #4
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
Nov 14 '05 #5
On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
<ja***@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
Nov 14 '05 #6
Jack Klein <ja*******@spamcop.net> wrote:
On Wed, 24 Nov 2004 22:25:18 +0100, jacob navia
<ja***@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 ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #7
In article <30*************@uni-berlin.de>,
<Je***********@physik.fu-berlin.de> wrote:
Jack Klein <ja*******@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 dj******@csclub.uwaterloo.ca

Right now? Either. Just fly out on your pig and buy one.
--Nick Maclaren in comp.arch
Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
1
by: Andre Janssen | last post by:
Hi.... I tried to compile the following src with this command: "g++ -Wall -o bla alsaswitch.cpp". The src is an example src of xosd package. #include <xosd.h> int main (int argc, char...
3
by: Michael Sgier | last post by:
Hi i get thousands of messages like below. How shall i resolve that? Thanks Mcihael Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int, int, char const*)':...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
2
by: zqiang320 | last post by:
Hello: I execute make ,then get error: $ make Making all in libsbml/src make: Entering directory `/home/internet/mydoc/test_pj/libsbml/src' ........ /bin/sh ./libtool --tag=CC --mode=link...
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.