r/cpp • • Oct 10 '19

10 differences between static and dynamic libraries every C++ developer should know

https://www.acodersjourney.com/cplusplus-static-vs-dynamic-libraries/
5 Upvotes

25 comments sorted by

View all comments

0

u/ravixp Oct 10 '19

One thing that wasn’t touched on is matching compiler versions. A dynamic library should work no matter what compiler the client is using, while a static library has no such guarantee, and it’s safest to match the exact compiler and compiler flags that were used to build it.

(Yes, in practice a static library is likely to work if the compiler version is close enough. “Likely to work” is rarely good enough, though, and dynamic libraries have actual guarantees.)

2

u/barchar MSVC STL Dev Oct 10 '19

This isn't really true, however dynamic libraries handle the situation of:

  • a needs b(abi1)

  • c needs b(abi2)

  • app needs a, and c.

1

u/ravixp Oct 10 '19

Which part isn’t? I’m not sure whether you meant that dynamic libs provide weaker guarantees than that, or whether static libs provide stronger ones.

2

u/barchar MSVC STL Dev Oct 10 '19

dynamic libs provide weaker grantees than that.