Purposes of using custom static/dynamic libraries in programming languages

Viewed 50

I am learning c++. So I'm a beginner. But I can't understand why programmers create custom libraries. I can easily get an answer to the question "how", but I can't get an answer to the question Why, I've found two possible reasons:

  1. Organizing subprograms (completed code pieces to one library) to use in different programms or tools, for example.
  2. Binary output size.

For organizing functional code blocks, I'd prefer to use git clone instead of a library. For me, it is a more comfortable way to integrate, edit, and use my code in different projects.

About output size: it's a controversial issue. If I use a static library, I don't get a smaller size because, using a static library, my app will be extended by byte code, but using native code, created code blocks will be converted as machine code and immediately added to the executable file. If we speak about DLLs, yes, you can reduce the output size, but you've got another issue. Loading in RT. I won't get any benefits.

Can you explain to me why?

1 Answers

You’re already writing libraries if you have multiple repositories that can be variously combined to form multiple programs. (This is an excellent idea: you never know when you’ll want to build a bigger program on top of current capabilities, and libraries compose much better than programs. What mechanism to use to compose source libraries is a different question.) Compiling them into binary libraries is mostly a matter of convenience, either because linking is cheaper than compiling or because it fixes things like preprocessor macros. It also avoids circumstances where two dependencies might otherwise require multiple copies of a third they both use.

Related