Visual Studio: What are lib files (used for)?

I am learning C ++ and stumbled upon those * .lib files that are obviously used by the linker. I had to install some additional dependencies for OpenGL.

  • What exactly are library files used in this context?
  • What is their content?
  • How are they generated?
  • Is there anything else worth knowing about them?

Or is it just nothing more than relocatable object code similar to * .obj files?

+4
source share
3 answers

Simply put, yes -.lib files are just a collection of .obj files.

There is a slight complication on Windows that two classes of lib files can have.
Static lib files essentially contain a .obj collection and are associated with your program to provide all the functions inside .lib. This is mainly a convenience that saves you so many files that you deal with.

There is also stub.lib, which provide only function definitions that are contained in the DLL file. The .lib file is used at compile time to tell the compiler what to expect from the function, but the code is loaded at runtime from the dll.

+8
source

.lib files are “libraries” and contain “collections” of compiled code that says so. Thus, this is a way to provide software components without issuing, for example, internal source code. They can be generated as “output” from the “assembly”, as well as executable files.

The specific content depends on your platform / development environment, but they will contain characters for the linker to “plug in” the function calls provided, for example. library header file.

Some libraries are "dynamic" (.DLL on Windows), which means that the "interception" of function calls is configured when loading an executable file using a library, which allows you to change the library implementation without restoring the executable file.

Last thing. You say you are learning C ++, and the common confusing point is that the “characters” generated by the C ++ compilers are “distorted” (in order to allow, for example, function overloading), and this “manipulation” is not it is standardized for different compilers, therefore libraries often resort to C for the "API" library (like OpenGL), although the library can be implemented in C ++ internally.

Hope to shed light on .lib files. Happy OpenGL coding :-)

+1
source

What are library files in this context used for?

They are compiled and linked by code, just like your executable. They are called static libraries that other programs can reference at compile time. In the case of OpenGL, you reference your libraries to create an executable file that can run OpenGL code. Dynamic Libraries (DLLs) are another type of library that is referenced for executable files except at run time.

What is their content?

Static libraries contain related object code, like exe. * .Obj files are the object code that the compiler creates for the linker.

How are they generated?

When the compiler creates object files, it passes the work to the linker. You can create them in your development environment, as well as executable files.

Is there anything else worth knowing about them?

Yes, they are used everywhere, so it doesn’t hurt to get used to them.

+1
source

Source: https://habr.com/ru/post/1303053/


All Articles