c++dlllinkershared-librariesstatic-libraries

What is the need for a library in C++?


Header files contain only the declaration of the function and the actual implementation of the function is in the library. If they don't want to share source code they can share the obj file. Why do we use a Library when the implementation of a function can also be done in another C++ file?


Solution

  • Usually, a library is a collection of several translation units. A library archive is simply a convenient way to bundle the separate object files into one blob.

    Besides that, shared libraries add the ability of dynamic loading and sharing of commonly used libraries between multiple dependents which isn't possible with a plain object file.