Program statically linked to a library but still needs dll to run

undu picture undu · Jun 15, 2012 · Viewed 11.2k times · Source

There are things that I don't understand when it comes to linking... I'm writing a program using a 3rd party library (the GEOS library). This program has a dependency to geos.lib but still needs geos.dll to run.

I read this question, I think I understand the difference between static and dynamic libraries. What I don't understand is why I still need a dll when I statically link a library.

Answer

BeReal82 picture BeReal82 · Jun 15, 2012

There are 3 kinds of libraries on Windows:

  • object library (*.lib)
  • import library (*.lib)
  • dynamic library (*.dll)

object libraries are statically linked. They contain the full object definitions of the code abstracted by the library.

import libraries is a special form of an object library. Instead of containing code they contain information for the linker that ultimately maps the executable file to the dynamic-link library.

dynamic link libraries, like object libraries, supply code for your program. However, this code is loaded at runtime and not compiled into your exe.

You don't always need to link an import library. Instead you can call LoadLibrary() and lookup the API entry points by name or ordinal. (You always have to tell the code which DLL and where in that DLL's API you want to enter.)

The other comments here are correct in that you cannot make a DLL into a static lib without recompiling the code for the libary -- it is a different kind of output.