Search code examples
c++windowsdllshared-librariesstatic-libraries

Build shared library with static library


Suppose I have a source code, and I compile it as a static library, so I have a .lib file. Let us call it first.lib.

Then I have other source code which is calling functions from the previous code. I build this code as a shared library and give the first.lib as an input to the linker. Now I have a second.lib, second.dll.

So far, so good, everything works. But I would like to create an EXE application, which is using the second.dll and the first.lib too. I link against the second.dll and give the first.lib as an input for the linker, when building the application.

Does my application contain the contents of the first.lib twice? In my case it seems like it does.


Solution

  • Does my application contain the contents of the first.lib twice?

    The answer is "kinda".

    When you link a static library, you are not including all of the library in the DLL or executable, only the parts you are actually using.

    So, parts of the static library is in the DLL, parts of the library is in the executable, and there are probably parts of the library that are in both.