The use of libraries is almost entirely
platform-specific, and even specific to your build
environment. However, it usually boils down to ensuring
that some headers are accessible with
#include
, and that some
precompiled translation units (modules) can be
linked with
the user's program. Such modules are usually grouped into
archives or compendia that can be linked with a program
as a single unit. These have suffixes such as
.a, .so, .lib and
.dll, depending on platform.
Command-line compilers often include an option such as
-Idir to add a directory
dir to a path which is searched for headers.
If the program attempts #include
<foo/bar.h>
, the compiler will look for
dir/foo/bar.h, for all
dir specified by
-I.
Another common command-line option is -Ldir to add directory dir to a path which is searched for precompiled modules. If an option such as -lfoo is used when linking, the linker will search for files such as dir/libfoo.a, dir/libfoo.so, dir\foo.lib and dir.o.foo (depending on platform), for all dir specified by -L.
There is some question over whether headers for external
libraries should be obtained with #include <>
or
#include ""
. A strict
interpretation of the standards would reserve
<>
for standard headers
only. [Citation required?] On
the other hand, <>
prevents
local files (i.e.,
relative to the #include
ing file) from
being included, so it exactly corresponds to what process
you'd expect to use to obtain external headers, whether
part of the C standard or not.