* Can't compile programs using functions in math.h
@ 2002-04-02 14:36 Martin Rothberg
2002-04-02 14:49 ` bjorn rohde jensen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Martin Rothberg @ 2002-04-02 14:36 UTC (permalink / raw)
To: gcc-help
I am running redhat 7.2. I can compile simple programs just fine, but I
cannot compile programs the use functions such as sin or cos. I need these
as I am doing navigation calculations. I have tried various things. I
confirmed that the compiler is finding math.h and the underlying
mathcalls.h. However, when I compile, I get:
[root@mercury root]# gcc -o junk test.c
/tmp/ccINr3XY.o: In function `main':
/tmp/ccINr3XY.o(.text+0x41): undefined reference to `cos'
collect2: ld returned 1 exit status
I am not sure why it fails. I have attempted to build both on command line
and via KDevelop (in case I forgot to set up something). Both yielded the
same result. I even reinstalled the RPM's for gcc in case I had damaged the
install, but the result was the same. Are there environment variables I
need to explicitly set to use the standard C headers and libraries? Since
the header files are intact, am I missing the library itself? Please advise
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can't compile programs using functions in math.h
2002-04-02 14:36 Can't compile programs using functions in math.h Martin Rothberg
@ 2002-04-02 14:49 ` bjorn rohde jensen
2002-04-02 15:05 ` Claudio Bley
2002-04-02 17:24 ` Ish Rattan
2 siblings, 0 replies; 4+ messages in thread
From: bjorn rohde jensen @ 2002-04-02 14:49 UTC (permalink / raw)
To: gcc-help
Hi Martin,
You need to link with the math library too, including the header is
not enough.
Try; gcc -o junk test.c -lm
Yours sincerely,
bjorn
Martin Rothberg wrote:
>
> I am running redhat 7.2. I can compile simple programs just fine, but I
> cannot compile programs the use functions such as sin or cos. I need these
> as I am doing navigation calculations. I have tried various things. I
> confirmed that the compiler is finding math.h and the underlying
> mathcalls.h. However, when I compile, I get:
>
> [root@mercury root]# gcc -o junk test.c
> /tmp/ccINr3XY.o: In function `main':
> /tmp/ccINr3XY.o(.text+0x41): undefined reference to `cos'
> collect2: ld returned 1 exit status
>
> I am not sure why it fails. I have attempted to build both on command line
> and via KDevelop (in case I forgot to set up something). Both yielded the
> same result. I even reinstalled the RPM's for gcc in case I had damaged the
> install, but the result was the same. Are there environment variables I
> need to explicitly set to use the standard C headers and libraries? Since
> the header files are intact, am I missing the library itself? Please advise
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can't compile programs using functions in math.h
2002-04-02 14:36 Can't compile programs using functions in math.h Martin Rothberg
2002-04-02 14:49 ` bjorn rohde jensen
@ 2002-04-02 15:05 ` Claudio Bley
2002-04-02 17:24 ` Ish Rattan
2 siblings, 0 replies; 4+ messages in thread
From: Claudio Bley @ 2002-04-02 15:05 UTC (permalink / raw)
To: gcc-help; +Cc: Martin Rothberg
>>>>> "Martin" == Martin Rothberg <merothberg@hotmail.com> writes:
Martin> [root@mercury root]# gcc -o junk test.c /tmp/ccINr3XY.o:
Martin> In function `main': /tmp/ccINr3XY.o(.text+0x41): undefined
Martin> reference to `cos' collect2: ld returned 1 exit status
You need to link in the math library, of course. Do this:
$ gcc -o junk test.c -lm
HTH
Claudio
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can't compile programs using functions in math.h
2002-04-02 14:36 Can't compile programs using functions in math.h Martin Rothberg
2002-04-02 14:49 ` bjorn rohde jensen
2002-04-02 15:05 ` Claudio Bley
@ 2002-04-02 17:24 ` Ish Rattan
2 siblings, 0 replies; 4+ messages in thread
From: Ish Rattan @ 2002-04-02 17:24 UTC (permalink / raw)
To: gcc-help
On Tue, 2 Apr 2002, Martin Rothberg wrote:
>
>
> I am running redhat 7.2. I can compile simple programs just fine, but I
> cannot compile programs the use functions such as sin or cos. I need these
> as I am doing navigation calculations. I have tried various things. I
> confirmed that the compiler is finding math.h and the underlying
> mathcalls.h. However, when I compile, I get:
>
> [root@mercury root]# gcc -o junk test.c
^^^^^^^^^^^^^^^^^^
add -lm to the end of the line above
-ishwar
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-04-03 1:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-02 14:36 Can't compile programs using functions in math.h Martin Rothberg
2002-04-02 14:49 ` bjorn rohde jensen
2002-04-02 15:05 ` Claudio Bley
2002-04-02 17:24 ` Ish Rattan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).