What are the differences in header and library files in C ++?

Closed due to the fact that the question’s essence is not clear to the participants by Vlad from Moscow , Alex , αλεχολυτ , user194374, aleksandr barakin 18 Dec '16 at 11:07 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    The question is not clear. - Vlad from Moscow
  • one
    What is a “library file”? - VladD
  • apparently library files, these are lib / a files. - KoVadim

1 answer 1

In short ...

The simplest and most obvious is that the header file is a plain text file, and the library file is a set of binary compiled object code.

The header file contains, as a rule, all declarations - types, functions, templates, etc. - everything that should be visible from several translation units, so as not to write this all in each .cpp-file.

The library contains a ready-made compiled code, which again can be connected to different projects in order not to compile it again.

So the header file reads and processes the compiler when compiling code into an object, and the linker is already engaged in the library.

  • But what about the header-only library? - αλεχολυτ
  • one
    @alexolut It’s hardly a child’s question "why the Earth is spinning around the Sun" makes sense to tell the general theory of relativity ... - Harry
  • You apparently forget that the answer is not only for the vehicle, but also for many other people who will get to this page later. - αλεχολυτ
  • @alexolut In this case, all the answers should be the same - just quoting the standard :) You, apparently, do not take into account that a person who has at least the slightest idea about header files and libraries will not look for an answer to this question. And yet - after all, my answer does not deprive you of the right to write a good, absolutely complete, with all the nuances of the answer! PS When you write your answer - do not forget that formally standard header files are not required to be text files and files in general. And about precompiled headers. And oh ... however, let's leave something for petty quibbles :) - Harry
  • I can not write an answer until the author has clarified the question. Collecting turnip on guesswork is not my method. Therefore, I voted to close the issue to clarify its essence. - αλεχολυτ