C/C++ libraries are modules of already-compiled code which are accessed through code you will write.
For example, TinyXML is a library that provides a lot of the functionality you would need to parse XML data, allowing you to work with XML without having to write your own parser.
Libraries come in two different flavours: static libraries and dynamic libararies.
A static library is specifically used at compile time, which means the libary must be present in the correct location (often but not always somewhere in your project folder) when you want to compile your C/C++ application, since it is compiled into the executable, and indeed, the compiler knows it must be there and will not compile without it. Under Windows, static libraries are usually suffixed .lib
, while under the *nixes (includes Android, iOS, MacOS), they are suffixed .a
.
A shared library is only required to be present for use at runtime. Which means you can compile your code without it. Since a shared library is not actually a part of your application's code (although your application may need it to run without failing), there is a certain overhead, however negligible, in accessing shared libraries (and it is downright negligible). When you run your favourite games, you will often see DLL files hanging out in the game's root folder, beside the executable. Those are shared libraries which the executable will need to use when you run it. Under Windows, shared libraries are .dll
. Under the *nixes, they are .so
. There are many differences undoubtedly, but the principle is the same, and most of the time from a coder's point of view they are not noteworthy.
Compiling libaries is another matter, which you can research once you've written a few simple programs in C or C++ and understand the bigger picture a little better. But generally speaking, it isn't too hard and is much like compiling an executable, only the code gets compiled into a non-executable file instead.