Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is a header only library [duplicate]

I am working on using boost C++ libraries for my next project and the documentation says that it is a header only library.

Most Boost libraries are header-only: they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking.

So my question is does it mean I do not need to link the library for these boost libraries and including the header is the only requirement ?

what are header only libraries and how are they different from the standard libraries that require building and linking to the binary ?

like image 809
cmidi Avatar asked May 05 '15 14:05

cmidi


People also ask

What means header-only library?

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.

Are header-only libraries good?

The benefit of header-only libraries is that they are easy to include in your project as you simply include the header and you are done (there is no need to compile the library as there are no source files to compile).

Why are some libraries header-only?

Having a header-only library also means you don't have to worry about different platforms where the library might be used. When you separate the implementation, you usually do so to hide implementation details, and distribute the library as a combination of headers and libraries ( lib , dll 's or . so files).

What does duplicate symbol mean in C++?

Solution. Duplicate symbols occur when you have both added an implementation file (. cpp) to your project and #included it. This way, the implementation file (. cpp) gets compiled twice: once as a module in your project (as it is added to your project) and subsequently as a piece of #included code.


1 Answers

A header-only library, as the name hints, is only made of headers. That actually means you don't have to link against binaries, because the whole code of this library is contained in headers, and this code will be compiled when you include them in your project.

This kind of libraries is sometimes the only way, for example when dealing with templates.

like image 146
JBL Avatar answered Sep 27 '22 22:09

JBL