i brand new c programming (but not programming) , trying understand how libraries , header files work together, particularly respect packaging , distribution.
after reading this excellent question , answer, understand header file(s) act api library, exposing capabilities outside world; , library implementation of capabilities.
however 1 thing cannot seem find explanation of is: how header files packaged or distributed libraries?
- are libs , headers packaged archive (zip, tarball, etc.)?
- are headers compiled libs , distributed alongside them?
when #include "mylib.h", how linker know find:
- the header file itself,
mylib.h - the library implementing functions declared in
mylib.h.
how linker know find: (1) header file itself,
mylib.h
- with notation
#include <mylib.h>, searches header file in system defined include path. - with notation
#include "mylib.h", searches header file in system defined include path , in current directory.
if header file present in other hierarchy, can provide path header file -i option gcc.
(2) library implementing mylib.h?
you need provide path library using -l (in case of non-standard path library) , link library using -l option.
as per convention, if (shared) library named libmylib.so, can use -lmylib link directory.
for example , consider pow() function.
it prototyped in math.h, in source file, need add #include <math.h> function declaration.
then, @ compile (rather, linking) time, need link "math" library using -lm function definition.
Comments
Post a Comment