What’s the difference between a header file and a library?

Think of both like this (Disclaimer: this is a really high-level analogy 😉 ..

  • The header is a phone number you can call, while…
  • …the library is the actual person you can reach there!

It’s the fundamental difference between “interface” and “implementation”; the interface (header) tells you how to call some functionality (without knowing how it works), while the implementation (library) is the actual functionality.

Note: The concept is so fundamental, because it allows you flexibility: you can have the same header for different libraries (i.e. the functionality is exactly called in the same way), and each library may implement the functionality in a different way. By keeping the same interface, you can replace the libraries without changing your code.

And: you can change the implementation of the library without breaking the calling code!

Leave a Comment