Home c++ why not all C++ Header-only libraries?

why not all C++ Header-only libraries?




Why not all C++ Header-only libraries?
Even Boost provides part of the functionality in the form of header-only libraries, and the part in the form of compiled.
And there are 2 questions:

  1. Are there any restrictions on header-only libraries?
  2. What type and when it is better to use?

Answer 1, Authority 100%

why not all C++ libraries are Header-only, you can understand, considering their advantages and cons

Pluses of using Header-Only Libraries:

  1. allows you to simplify the delivery of libraries for the client, since the client itself can compile the source file with the desired settings for the desired platform.

  2. Allows the compiler to make more optimizations, in particular inline, which is not possible when dividing libraries to implementing files and interface, but you are at risk of inflating the executable code due to the use of this header file in many units of broadcast, but most of the smart compilers are smart and can avoid it.

  3. When adding Header-only to the project requires only Include-paths.

Disadvantages of using Header-Only Libraries:

  1. You can not hide the implementation details, how can this be achieved when dividing the library to the interface in the .h file and the implementation file supplied for example in the form of .lib , .dll .

  2. Most changes in the library will require recompilement of all compilation units using this library.

  3. longer compilation time, as the compiler should see the implementation of all components in the included files, and not just their interfaces.

  4. is complicated by reading the code, since the client is easier to see only the interface of the functional used and not to be distracted by the implementation (controversial statement).

  5. You can not jumble dynamically = cannot be replaced / updated the library in the already compiled program.

When from using Header-Only Libraries Not anyway:

  1. When using templates (Template ), the title definitions are the only way to compile (if there is no explicit instance of templates), since the compiler must know the full definition of templates to instance the template.

Based on the foregoing, everyone can make a conclusion for themselves, use Header-only or not, I believe that using the Header-Only Library is not the best solution in most cases, if you just do not need templates or inline functions.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions