When to use dynamic vs static libraries in C++?
Hi everyone! I'm just starting to learn C++ and project building, and I'm confused about libraries. I think I understand that there are static (.lib, .a) and dynamic (.dll, .so) libraries, but I can't figure out when to use which in practice.\n\nFor example, I'm writing a small project — a console calculator. I'm using a library for mathematical functions (let's say my own). If I link it statically, the code just gets copied into my .exe. If dynamically, the library will be a separate file. What's the benefit?\n\nOnline sources say that static libraries make the exe larger, while dynamic ones make it smaller, but that's not the only difference. I've also heard that DLLs can "break" when updated, while static ones don't. But then why are dynamic libraries needed at all if they're unreliable?
No answers yet.
Log in to leave an answer