Ashwin Nanjappa
Ashwin Nanjappa

Reputation: 78498

Visual C++: What is a dynamically linked .lib file?

I noticed the following about a library I use:

I open the .sln (solution) file of the library (it is open source) and see the following in its Project properties:

  1. Runtime Library option is set to Multi-threaded (Debug) DLL.
  2. Configuration Type is set to Static Library (.lib)

My confusion is:

  1. Isn't there a conflict in the library options above? (Static Library says one option, DLL says another)
  2. What kind of an animal is a .lib that is dynamically linked? How is it different from a DLL?

Note that I am aware of the difference between static libraries and dynamic libraries in the Linux world.

Upvotes: 0

Views: 425

Answers (3)

Pontus Gagge
Pontus Gagge

Reputation: 17258

A Windows DLL can be dynamically loaded with the LoadLibrary (or LoadLibraryEx) API, but then you have to find and bind each exported function to a function pointer using GetProcAddress or GetProcAddressEx. You'd better get the function signatures right, or Bad Things Will Happen, as usual.

A LIB file allows Windows to do all that for you when your EXE is started (including finding which DLL to use, and recursively loading dependent DLL's), linking the dynamic library statically at run time, while avoiding bloating your EXE file with the executable code, and allowing several processes to share the same DLL image in memory.

Upvotes: 2

MSalters
MSalters

Reputation: 179779

The "RunTime Library" option isn't about YOUR library. It tells the compiler that you'll import your functions from MSVCRTxx.DLL at runtime.

The "configuration Type" option does refer to your library, and therefore is independent of the "RunTime Library" option.

Upvotes: 3

anon
anon

Reputation:

I don't know about the config mismatch, but a .LIB file when created with a .DLL library is an "export library" - it doesn't contain any code, but just the names of the callable functions and objects in the DLL. The linker uses this to satisfy references at link time which are finally resolved by dynamic loading at run-time.

Upvotes: 1

Related Questions