public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with header files.
@ 2001-08-03 16:32 Matt R
  2001-08-03 16:43 ` David Berthelot
  2001-08-03 16:49 ` Alexandre Oliva
  0 siblings, 2 replies; 4+ messages in thread
From: Matt R @ 2001-08-03 16:32 UTC (permalink / raw)
  To: gcc-help

Dear GCC Gurus, 
I have a problem getting GCC to refer to header files.
For example the following program....
------------Code Begins Here------------
#include <stdio.h>
#include <math.h>


main() {
    float uno;
    float  duo;
    uno=7.778;
    duo=sqrt(uno);
    printf("sqrt of %f is %f \n", uno, duo);
}

------------Code Ends Here--------------
Produces the following message at compile time...

[fakeuser@fakehost BeginC]$ gcc trial.c
/tmp/ccBm2UFL.o: In function `main':
/tmp/ccBm2UFL.o(.text+0x1b): undefined reference to `sqrt'
collect2: ld returned 1 exit status */

__________________________________________

What is going on?  I would really appreciate your advice on this
one.  I have to admit to being a newbie to C programing.
I have installed glibc 2.2.12 (full install), and gcc 2.9.6-85, and 
am using RedHat 7.0 distro.  The original versions of glibc gave the 
same errors.

Looking forward to your advice...otherwise I will end up doin my
iminent assignments on DOS....a fate worse than death.

Matt Redding

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with header files.
  2001-08-03 16:32 Problem with header files Matt R
@ 2001-08-03 16:43 ` David Berthelot
  2001-08-03 16:49 ` Alexandre Oliva
  1 sibling, 0 replies; 4+ messages in thread
From: David Berthelot @ 2001-08-03 16:43 UTC (permalink / raw)
  To: nimrod99; +Cc: gcc-help

Ok I think it's quite easy: you forgot to specify the library for
linking, you should do:

gcc trial.c -lm

libm is the math library, when referring to a library you put -l
(instead of lib),
so -lm link with the math library.

David

Matt R wrote:

> Dear GCC Gurus,
> I have a problem getting GCC to refer to header files.
> For example the following program....
> ------------Code Begins Here------------
> #include <stdio.h>
> #include <math.h>
>
> main() {
>     float uno;
>     float  duo;
>     uno=7.778;
>     duo=sqrt(uno);
>     printf("sqrt of %f is %f \n", uno, duo);
> }
>
> ------------Code Ends Here--------------
> Produces the following message at compile time...
>
> [fakeuser@fakehost BeginC]$ gcc trial.c
> /tmp/ccBm2UFL.o: In function `main':
> /tmp/ccBm2UFL.o(.text+0x1b): undefined reference to `sqrt'
> collect2: ld returned 1 exit status */
>
> __________________________________________
>
> What is going on?  I would really appreciate your advice on this
> one.  I have to admit to being a newbie to C programing.
> I have installed glibc 2.2.12 (full install), and gcc 2.9.6-85, and
> am using RedHat 7.0 distro.  The original versions of glibc gave the
> same errors.
>
> Looking forward to your advice...otherwise I will end up doin my
> iminent assignments on DOS....a fate worse than death.
>
> Matt Redding

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with header files.
  2001-08-03 16:32 Problem with header files Matt R
  2001-08-03 16:43 ` David Berthelot
@ 2001-08-03 16:49 ` Alexandre Oliva
  2001-08-03 17:52   ` Problem with header files. YeHaaaaaa!!!!! Matt R
  1 sibling, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 2001-08-03 16:49 UTC (permalink / raw)
  To: nimrod99; +Cc: gcc-help

On Aug  3, 2001, Matt R <nimrod99@dingoblue.net> wrote:

> I have a problem getting GCC to refer to header files.

No, your problem is not about header files, it's about libraries, that
are a completely different thing.  Headers supply declarations or
inline implementations; libraries supply implementations for functions
that are only declared in headers, or that fail to be inlined.  The
library in which sqrt() is defined is the math library, that you can
link in by adding `-lm' to the link command.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with header files. YeHaaaaaa!!!!!
  2001-08-03 16:49 ` Alexandre Oliva
@ 2001-08-03 17:52   ` Matt R
  0 siblings, 0 replies; 4+ messages in thread
From: Matt R @ 2001-08-03 17:52 UTC (permalink / raw)
  To: Alexandre Oliva, David Berthelot; +Cc: gcc-help

Thankyou  very much.

Thanks to you the pain is over.
Great to see you are still able to put up with
newbie questions...as dumb as his one.

If you have got
a question about soil contamination
or soils in general, I'd be glad to try to answer you.
But I am very much a begginer with c and gcc.

Thanks, 

Matt Redding

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-08-03 17:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-03 16:32 Problem with header files Matt R
2001-08-03 16:43 ` David Berthelot
2001-08-03 16:49 ` Alexandre Oliva
2001-08-03 17:52   ` Problem with header files. YeHaaaaaa!!!!! Matt R

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).