Theory: Class Libraries

Learn about class libraries and their organization.

What are Class Libraries? What are the different ways to organize them?

Class libraries are related classes compiled into object code. For example, the classes like ostream and istream that have been compiled into the C++ standard library. Many third-party class libraries are also available for purchase. For example, a class library for fingerprint recognition, a class library for 3D animation, or a class library for text to speech conversion.

We can even create libraries out of our classes. Class libraries can be either statically linked or dynamically linked.

Statically Linked Libraries: These become part of the executable code that uses the library. So, if there are three programs that use a statically linked class library, the class library would become part of all three executables. This is not a good idea. This is because, if all three executables are executed then three copies of the same library would be present in memory.

Dynamically Linked Libraries: If three executables use a dynamically linked library then the library is loaded in memory only when the first executable is loaded. When the three executables are running all three would share one single copy of the library.

The statically-linked libraries have a .LIB extension under Windows and a .a extension under Linux. The dynamically-linked libraries have a .so extension in Linux environment and .dll extension in Windows.

Get hands-on with 1200+ tech skills courses.