In the context of the C or C++ programming languages, a library is called header-only if the full definitions of all macros, functions and classes comprising the library are visible to the compiler in a header file form, with no separate implementation files or precompiled binaries. Header-only libraries do not need to be separately compiled, packaged and installed in order to be used. All that is required is to point the compiler at the location of the headers, and then the header files into the application source. Another advantage is that the compiler's optimizer can do a much better job when all the library's source code is available. Because the compiler has direct access to the implementation, it can inline more code, which can make the compiled executable faster.
Compiling the library's code directly allows for more efficient inlining, potentially resulting in faster executable code due to the elimination of function call overheads.
The disadvantages include:
Nonetheless, the header-only form is popular because it simplifies code distribution and re-use by avoiding many of the problems associated with packaging and linking external code.
For C++ templates, including the definitions in header is the only way to compile, since the compiler needs to know the full definition of the templates in order to instantiate.