I'm looking for information about C ++ libraries, but when I've read them I see missing headers like windows.h. What is the difference between a library and a header?
I'm looking for information about C ++ libraries, but when I've read them I see missing headers like windows.h. What is the difference between a library and a header?
A header file (which in the C ++ literature is called header
) is a file that contains mainly function declarations, type definitions and macros. Provide the API with which you access the functions, classes and macros of a library.
A "library" is actually a biblioteca
, only sometimes it is called a library because it is written similar to "library", in English, but do not let it confuse you; when someone talking about C ++ says "library" is referring to a library, which is a collection of classes and functions.
A library is usually composed of object files (already compiled) and "header" files, which are "included" (#include) in your .cpp and .h files.
Example prayer:
In order to use
cout
in your program, you must include the file of header<iostream>
, which is a file that is part of thebiblioteca estándar
of C ++.
What is the difference between a library and a header?
hpp
1 , normally (ideally) it only has statements of functions or objects. Sometimes libraries are provided by third parties and contain, in addition to headers, pre-compiled code in the form of dll
or lib
to be used for link (dynamic or static link, respectively).
I see missing headers like windows.h
C ++ is a compiled language so once the program is generated, it is not modified. This means that the same code can not be adapted to different operating systems (unlike the languages interpreted or those that use virtual machine ), but to use it in different operating systems Compiled with the headers of this operating system.
Usually the compilers installed in the system already provide the necessary headers for it, otherwise the installation is incomplete, erroneous or there is a configuration failure. You should check the details of your compiler to be sure.
1 Although the extension is indifferent, an arbitrary extension can be used.
What is the difference between a library and a header?
In C ++ you could integrate the entire program into a single file ... but this leads to a series of drawbacks:
It is for these reasons that the program is divided by functionalities or classes. Even so, imagine that, for example, in the case of classes, both the declaration and the implementation are left in a single file ... this practice has certain drawbacks:
So what is usually done is to separate the declarations of the implementations. When doing this division, a change in the implementation (for example the correction of an error), only entails the recompilation of a file.
Strictly speaking, C ++ does not determine which format extension each file should have. However, a series of conventions have been acquired over time. So:
I see missing headers like windows.h
The pages with documentation about the bookstores usually cover only the set of libraries contemplated by the standard.
The headings of the Operating System or third parties are usually not covered by these pages. This documentation is usually found on the author's own page. So, for example, to investigate about WinAPI, go to the MSDN and to investigate about Boost, we went to your website .
It does not make sense that these libraries are documented in generic pages for several reasons:
So, whenever you need to get out of the standard, you will have to resort to alternative sources of documentation to know the new architecture you are going to use.
During the construction of the application, the preprocessor includes the header files in the sources. Subsequently, during the linking phase, the linker includes in the executable the modules corresponding to the functions and library classes that have been used in the program, so that the whole becomes part of the executable.
That's the main difference.
With the two libraries can be implemented.
Greetings,