views:

37

answers:

3

I noticed the following about a library I use:

  • Library is compiled to .lib file.
  • My code needs to be compiled as Multi-threaded (Debug) DLL to link to this library.

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.

+1  A: 

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.

anon
I am not able to see any DLL file of this library anywhere. Yet, my code can link to the .lib and execute! Am I missing something?
Ashwin
@Ashwin Sounds like you have a static library then. The best bet is to examine your executable with Dependency Walker a free tool from avaialble at http://dependencywalker.com/ and see what it is actually depending on.
anon
Ashwin
@Ashwin I know nothing about wxWidgets, so I can't help there I'm afraid.
anon
+2  A: 

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.

MSalters
A: 

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.

Pontus Gagge