Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm learning C++ and came across those *.lib files that are obviously used by the linker. I had to set some additional dependencies for OpenGL.

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

Or are they just nothing more than relocateable object code similiar to *.obj files?

like image 399
rak Avatar asked Mar 03 '10 21:03

rak


Video Answer


1 Answers

In simple terms, yes - .lib files are just a collection of .obj files.

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

There are also stub .lib which provide just the definitions of functions which are contained in a .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 run time from the dll.

like image 141
Martin Beckett Avatar answered Oct 25 '22 17:10

Martin Beckett