Connecting Tech Pros Worldwide Forums | Help | Site Map

Difference between a library file and a header file in C

s.subbarayan
Guest
 
Posts: n/a
#1: Nov 14 '05
Dear all,
How different is a header file from a library file in C?Under what
circumstance u go for library and under what circumstance u go for
header?Afaik,both have some declarations which can be called from a
source file.And what should I do if i want to build a library?Is it
that jus setting the compiler option to be library makes u to create a
library or u have to do something in the code to create a library?
I am sorry if it looks nerd but I thought better learn now then late.
expecting all ur replies and advanced thanks for the same,
Regards,
s.subbarayan

Neil Kurzman
Guest
 
Posts: n/a
#2: Nov 14 '05

re: Difference between a library file and a header file in C




"s.subbarayan" wrote:
[color=blue]
> Dear all,
> How different is a header file from a library file in C?Under what
> circumstance u go for library and under what circumstance u go for
> header?Afaik,both have some declarations which can be called from a
> source file.And what should I do if i want to build a library?Is it
> that jus setting the compiler option to be library makes u to create a
> library or u have to do something in the code to create a library?
> I am sorry if it looks nerd but I thought better learn now then late.
> expecting all ur replies and advanced thanks for the same,
> Regards,
> s.subbarayan[/color]

Header File let the compiler know the prototype for function in a
library. Plus other need definitions.
A library is just a collection of functions.

If you want to make your own statically linked library. group your
functions in a project, with no main() and build it as a library. Note
that the linker brings in a entire code module at a time. This means if
you put 20 functions a a single C file and make it into a library, then
call 1 function you get all 20. if you make the library out of 20 C file
of 1 function each, you only get the 1 file.

Dynamically linked libraries are similar, but do not get linked into you
exe.


SM Ryan
Guest
 
Posts: n/a
#3: Nov 14 '05

re: Difference between a library file and a header file in C


s_subbarayan@rediffmail.com (s.subbarayan) wrote:
# Dear all,
# How different is a header file from a library file in C?Under what

The header file is C code which defines the interface to the code.
The library is resource in some language, not necessarily C, which
implements the interface, and which is comprehensible to a loader/linker
for inclusion in your programs. A library will often be a translation
of C source file(s) which might be distributed with, or instead of, the
library file(s).

# circumstance u go for library and under what circumstance u go for
# header?Afaik,both have some declarations which can be called from a

There is no rule: it is up to you. You can write functions in header
files that get compiled into each source file that includes the header.
You can also put only the function prototype in the header and the
actual function in a library. It's up to you.

# source file.And what should I do if i want to build a library?Is it
# that jus setting the compiler option to be library makes u to create a

It depends on your system, Sometimes it's easy, sometime's hard, but
it rarely be the same on different systems.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
CBFalconer
Guest
 
Posts: n/a
#4: Nov 14 '05

re: Difference between a library file and a header file in C


"s.subbarayan" wrote:[color=blue]
>
> How different is a header file from a library file in C?Under what
> circumstance u go for library and under what circumstance u go for
> header?Afaik,both have some declarations which can be called from a
> source file.And what should I do if i want to build a library?Is it
> that jus setting the compiler option to be library makes u to create a
> library or u have to do something in the code to create a library?
> I am sorry if it looks nerd but I thought better learn now then late.
> expecting all ur replies and advanced thanks for the same,[/color]

If you want to be taken seriously try using English. 'u' and 'ur'
etc. are not English words, and make things hard to read.
Following sentences with blank space also helps. The use of
geek-speek simply makes you look ignorant.

Header and libraries are entirely different things.

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


Dan Pop
Guest
 
Posts: n/a
#5: Nov 14 '05

re: Difference between a library file and a header file in C


In <c396173e.0405192027.1e2c96d1@posting.google.com > s_subbarayan@rediffmail.com (s.subbarayan) writes:
[color=blue]
>How different is a header file from a library file in C?Under what
>circumstance u go for library and under what circumstance u go for
>header?[/color]

Header files are for compiler consumption and contain C source code.

Library files are for linker consumption and contain object code
packaged in a special format, so that linkers can extract only the parts
needed by the other object files involved in the linking process.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
Closed Thread