I am new to programming. learning C as of now. I understand that header file only contains the declarations and function prototypes, not the functions themselves. Am I correct?
I understand that Library is a single file that contains different object codes. Are these object codes necessarily written only in C language or other languages can also be used to generate such object codes?
On linking, does the entire library file get attached to the executable or just the object codes declared in the header file?
Usually, yes (although you can theoretically put any code you want in a header file). Remember that a header file is usually just
#include-d into a source file, and#includeis basically equivalent to a copy-and-paste.Not necessarily. “Library” is a bit of a loose term, but generally speaking, it’s used to describe a collection of functions (and potentially data) that together perform some useful set of tasks. These functions may be defined in one or several source files. Typically, a library is pre-compiled into a standalone object file. But again, not necessarily.
No. They can be written in any language (because it will always be compiled down to raw machine code). But if you want to use the library from C, then certain compatibility requirements must be fulfilled, to ensure that the C compiler knows how to call the library functions correctly.
Sometimes. This is what’s known as static linking. The other main type is dynamic linking, where the library object code is linked at run-time.