Difference between a library file and a header file in C

S

s.subbarayan

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
 
N

Neil Kurzman

s.subbarayan said:
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

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

SM Ryan

(e-mail address removed) (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.
 
C

CBFalconer

s.subbarayan said:
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,

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

Dan Pop

In said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top