Hello. Files (for connecting functions from libraries and packages. In C ++) with the extensions .lib and .dll are not obviously included in the Standard C ++ library?
3 answers
To begin with, let's break down the concepts.
The .lib format is the format of a static library adopted by MSVC (possibly by other compilers), that is, a library that will be compiled by the linker into an executable module. Other compilers (especially on other systems!) May have a different format of static libraries.
The .dll format is the system-wide format of dynamic libraries adopted by the Windows operating system, that is, libraries that are connected at runtime . Compilers that produce code for Windows usually (but not always, of course) produce dynamic libraries in this format. (On other systems, the dynamic library format is clearly different.)
The C ++ ranttime library is a set of standard functions that must be available to the program.
Static / dynamic libraries are not specified in the C ++ language standard (not to be confused with the standard library!), Its runtime library can be implemented as desired by the authors of the compiler. In practice, however, the current versions of MSVC implement the runtime library in both static and dynamic library formats.
In MSVC, you can produce and use any library, static (.lib) and dynamic (.dll). Since the runtime library is in both versions, you can, if you wish, any of them.
Thus, both .dll and .lib can contain both the standard library and anything else.
It became clearer?
(Delivered from the comment, does not fit). When you connect .h, you declare the presence of some functions. For a linker to find these functions, they must be somewhere.
If these functions are in your code in another .cpp-file, everything is already in order.
If these functions are in the runtime library, you need to connect it as a static or dynamic library. (But in the project it is already connected, the standard MSVC project connects runtime. Or it does not connect if you selected this option.)
If you connect something else, then you yourself have to connect the library, which contains the necessary functions, otherwise the linker will not be able to find them.
That is: you need to connect, just some libraries (for example, runtime) are connected by default.
- About static and dynamic clear to me. I am interested in all this, because I am afraid of the question on the exam: why can the .h files be connected simply with a hook, while others are not? More precisely, why can't .dll and .lib be made the same as .h (roughly speaking, change the extension)? What's the Difference? - cherry cherry rainbow
- @alias: added to the answer. - VladD
- through include you can include any files. Even dll. But only it most likely will not compile. You do not need to think that include is something very clever - it is just a substitution of the file contents into the given string and no more. - KoVadim
- @KoVadim: if there are only templates in the header, it may not be necessary to connect the library. In general, there are many subtleties, but top-starters need to first understand the basics of the basics. - VladD
- Read my comment again. By the word connect, I meant #include "file.dll" and this preprocessor will skip. And even, perhaps, the compiler will try to do something (after all, inside a file with the dll extension, there may not be a dll at all, but a plain text file). and .h is nothing more than a convention. - KoVadim
And why should they enter the standard? These are implementation details on a specific platform (in this case, on Windows). Therefore, the phrase "already known" sounds strange.
Looked at the current standard. There is no word about dll / lib.
- 7> Looked at the current standard. There is no word about dll / lib. I would be wildly surprised if it were said. - skegg
- he himself would be surprised. But the vehicle wrote so interestingly “already knowingly” that it became interesting to me, maybe I missed something in this life. - KoVadim
As far as I understand, in MSVC
* .lib is an archive file that generally stores a set of "external character" mappings - a link to an object (COFF or PE) file. This “character” at the linking stage is either added to the executable image (in the case of COFF, from the precompiled object file), or it is written in the import table (in the case of PE). Those. some amount of external links is translated into your exe
or dll
, through a set of archive rules. Libraries, by and large - this is not, although it is called, oddly enough:
The COFF archive format provides for the collections of object files. These collections are commonly called libraries in programming documentation.
Source: Microsoft Portable Executable and Common Object File Format Specification