Complete.Org: Mailing Lists: Archives: linux-help: August 2002:
[linux-help] Re: A c problem
Home

[linux-help] Re: A c problem

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: linux-help@xxxxxxxxx
Subject: [linux-help] Re: A c problem
From: bruce <bbales@xxxxxxx>
Date: Mon, 5 Aug 2002 17:00:53 -0500
Reply-to: linux-help@xxxxxxxxx

That helps a lot.  
Thanks, Steve
bruce


> Part of the confusion is the difference between a header file and a
> library. A header file (.h) generally contains macros or definitions
> (#define) and/or function prototypes, type definitions, etc. It
> generally doesn't include the code that actually implements the
> functions. The implementation of the functions are in the libraries in
> the form of compiled object code.
>
> So, if you want to use a function that exists in a library, you
> generally must include a header file that contains the function
> prototype and any definitions, and you must link to the object code in
> the library during the compile process.
>
> The linker in gcc automatically links to the standard C library, so
> you do not have to explicitly do that. Header files like stdio.h,
> string.h, stdlib.h all contain definitions for stuff in the standard C
> library. The math library, however, is not automatically linked, and
> that is why you need to specify to gcc that you want to link to the
> math library (-lm). Including math.h includes the definitions and
> prototypes for the math library, but does not actually cause the
> library to be linked.
>
> That will cover most, if not all, of the examples in the K&R
> book. Basically, if you try to compile something and you get an error
> similar to what you were getting, it probably means that you need to
> tell gcc to link to some library. The libraries are stored in files
> that are named something like libm.* (math library). When you use the
> -l option on the gcc command line you skip the "lib" part. That is why
> it is just -lm.
>
> I hope that helps.
>
> Steve
>
> > Thanks,
> > bruce
> > -- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
> > visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
>
> -- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
> visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
-- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]