473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Difference between a library file and a header file in C

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
Nov 14 '05 #1
4 2584


"s.subbarayan" wrote:
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.
Nov 14 '05 #2
s_**********@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?
Nov 14 '05 #3
"s.subbarayan" wrote:

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.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #4
In <c3**************************@posting.google.com > s_**********@rediffmail.com (s.subbarayan) writes:
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: zealot | last post by:
What is the relation/difference between a header file, dll and library?
24
by: RHNewBie | last post by:
Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2. Thanks.
9
by: bill | last post by:
Forget the exact definition of difference between, #include <foo.h> and #include "bar.h" Normally foo.h is a standard header file, so it's path is not defined in compiler option, but I...
23
by: yezi | last post by:
Hi, all: The 1st sendtence: int main(){ char string={""}; string = {" connected "}; ..... }
3
by: Xiaoshen Li | last post by:
Dear All, I saw some people using #include <string.h> some people using #include <cstring> What is the difference between the two? I can find the file string.h at /usr/include. I don't...
2
by: david wolf | last post by:
My understanding is that cstdio basically is the same as stdio.h except the functions are in a namspace called std. However when I take a look at the content of the file cstdio, it has the...
3
by: albert.neu | last post by:
Hello! What is the difference between "library parts" of C99 and "language parts" of C99. see...
11
by: sunnyalways4u2000 | last post by:
hello sir, Sir will please tell me the exact difference between C and advanced C...what are the extra features or funcions...etc added in this advanced one.
16
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.