How software libraries work?

  Рет қаралды 9,112

Smok Code

Smok Code

Күн бұрын

In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development.
Programming Libraries are nothing new - they have been around for roughly 70 years, and they’re used by almost all programs written today. Even the simplest helloworld program written in C++ is using multiple libraries. Some of them most likely - you never heard of.
So what are software libraries, and how do they work? Obviously you already know they are pieces of code written for you by some other developer, so you don’t have to do everything from scratch. And to be fair: most programmers won’t need to bother themselves with details how this works. Well at least until it doesn’t. Then my friend, you open the hatch to figure out what is going on, and boy oh boy. Things get a little overwhelming. So today we’ll look into these building blocks that make up our environment and let us do our job.
#programming #tech #softwaredevelopment
refspecs.linuxbase.org/elf/elf...
en.wikipedia.org/wiki/Executa...
First, we have code-generation libraries. These are special tools that read configuration stored in the code, or externally to create more code that will be later read to the compiler. Example in java could be: project lombok, mapstruct library, or tools like xtext, For C# you’ll find powerful T4, and for C++ - well, there are libraries that work on preprocessor level like GTest, and some could argue that the whole template system is nothing else but a glorified code generation tool.
Static libraries come second. They are also called compile-time libraries and for a good reason: they’re permanently sewn into the machine code of our program’s executable during the compilation. Machine code compiled from your source will be merged with machine code of libraries during the linking process into a single binary file.
Dynamic libraries are a little different: Linker reads them when building your binary to check if everything is correct but it doesn’t actually add libraries to your code. They belong to the operating system, and often multiple programs use the same libraries (that’s why they are also called shared objects). Whenever a user runs your program - the operating system will check if perhaps the library is already loaded, because another process is using it. If that’s the case - it will share the library's address with your program. Otherwise it will just load it before running your code.
Now let’s talk briefly about remote libraries. These allow programmers to use RPCs or remotely called procedures. While code of such a library can actually run on the same machine, it has substantial overhead compared to say dynamic libraries. All this gets justified if you can benefit from distributed architecture. Simplest example is your trusty database: your program most likely has a database client, and this client is calling the database server remotely to fetch some data. There are whole frameworks that support writing such libraries, for example gRPC.
Today I want to dive a tad deeper into shared libraries. This is what my recent work in Cisco is currently about: I’m putting one of our services written in C++ into a Docker container, and correctly managing shared libraries is really a huge part of the task.
As I have mentioned before: even the smallest program like hello world uses libraries, and shared ones too. So let’s try it. I’ll spin up a docker container and we’ll take a look at these shared libraries.
For my docker image I’m using ubuntu with builtin clang-12, my current go-to compiler for C++. I’ll add two packages here: paxutils and ncurses-library. Paxutils brings some useful tools to analyse binaries, and ncurses is just an exemplary dependency I’ll use in my code to color text output.
As promised I’ll compile a simple hello world program: nothing fancy, just plain string sent to standard output. I can compile this from the command line and I’ll use a standard tool to list dependencies: LDD.
As you can see: there are few libraries that are used here: kernel vdso (virtual dynamic shared object), standard C++ library, libm (c math library), gcc (low-level runtime library), libc (c-standard library) and lastly: interesting ld-linux…..so.
This last row is a clue to what we’re after: dynamic linker library.
- Wait. What is that dynamic linker?
- This is the system component that is responsible for finding dynamic libraries that the program wants to use. Interesting fact is - that each program decides which linker is going to handle dependencies.
- Wait so there are multiple dynamic linkers?
Well, fortunately not really, no. In practice we use one linker in the operating system. But here’s the catch: binaries in linux follow the ELF standard, and it says that binaries contain sections, and in one of these sections every binary defines a program interpreter.

Пікірлер: 19
@aloufin
@aloufin 3 жыл бұрын
shot of whisky everytime smok says 'libe-laries' ! awesome video, keep it up =)
@SmokCode
@SmokCode 3 жыл бұрын
Lawl! I'm actually working on my weird accent with a dedicated tutor, stay tuned and see how it evolves!
@Mr_SSK
@Mr_SSK 2 жыл бұрын
The background is damn cooool.. Anyways, the explanation was really helpful!
@pepe6666
@pepe6666 5 ай бұрын
i am loving these breakdowns. just explanation of how the architecture works from a meaningful context - its so useful. also i love the way you say libraries. thanks for the insight to see that this needed to be explained in this manner.
@breakingmhet8078
@breakingmhet8078 3 жыл бұрын
super helpful, thank you!
@MrAman47
@MrAman47 Жыл бұрын
After listening to you say "liblary" 40 times in this video, I can now say that I also say "liblary". Great video btw!
@wanfaradiba2650
@wanfaradiba2650 2 жыл бұрын
what software did use by application computerized library system?
@eclipsetutorialvideo
@eclipsetutorialvideo 3 жыл бұрын
Could you please explain why you needed to go inside the dynamic libraries to make your cpp program work in your container? What error did you meet? By the way to use the same image do : docker pull clangbuiltlinux/ubuntu Thanks
@SmokCode
@SmokCode 3 жыл бұрын
Sure. When you're docker container - you're using certain distribution of OS, with only few libraries that are available. More complex programs use a lot of libraries, some of them are available as dynamic. In this case I was debugging why postgresql client lib didn't work with my program. I found out that postgres depends on kerberos, which was installed in my system, but in an incompatible version. So now I could either switch the kerberos version or change the version of postgres to match what I had in the system. Other way is providing a directory for dynamic linker to show where your custom versions are, but that's another can of worms.
@eclipsetutorialvideo
@eclipsetutorialvideo 3 жыл бұрын
@@SmokCode Thanks for having provided the context :) I never thought that learning how libraries are used could be so different. Could we say that loading .net libraries are dynamic then?
@kukiezi
@kukiezi 3 жыл бұрын
Wow, I have never heared about most of those things while learning on university or in my first two jobs. If I may ask, did You learn about those things beacause it was needed for specific job or do You just read about those topics in your free time :D
@SmokCode
@SmokCode 3 жыл бұрын
I needed this so my docker container works correctly on few old machines (debian jessie).
@kukiezi
@kukiezi 3 жыл бұрын
@@SmokCode Thank You. Great video and explanation. Tho one really needs to read more about that to get into the topic deeply.
@mshingote
@mshingote 3 жыл бұрын
Which book you were referring in this video?
@SmokCode
@SmokCode 3 жыл бұрын
Welcome on the channel! These are good sources: refspecs.linuxfoundation.org/elf/elf.pdf (ELF spec) amzn.to/3mZnsNN (Linkers and Loaders by Levine)
@mshingote
@mshingote 3 жыл бұрын
@@SmokCode Is there any similar available for windows platform?
@SmokCode
@SmokCode 3 жыл бұрын
You can use the official reference for PE format (exe, dll and other) docs.microsoft.com/en-us/windows/win32/debug/pe-format I don't know which book is a good one for windows.
@ROSALIEIK
@ROSALIEIK 7 ай бұрын
its new to me lol.
@sandipansarkar9211
@sandipansarkar9211 3 жыл бұрын
too advanced
How to make a GOOD Code Review?
7:29
Smok Code
Рет қаралды 22 М.
How To Be A GREAT Programmer
17:41
Continuous Delivery
Рет қаралды 75 М.
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 49 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 73 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 31 МЛН
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 12 МЛН
Write Better Code!  |  How to Create Shared Libraries in C/C++
13:59
Low Level Learning
Рет қаралды 52 М.
Code Libraries - Computerphile
8:45
Computerphile
Рет қаралды 92 М.
Malware Development: Processes, Threads, and Handles
31:29
How-To Use C++ Libraries (without relying on a package manager)
30:22
Code, Tech, and Tutorials
Рет қаралды 52 М.
Design of the platform business | Paul von Gruben | TEDxTUBerlin
14:20
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,6 МЛН
Getting Started With Shared Libraries in Jenkins
23:23
CloudBeesTV
Рет қаралды 75 М.
What are libraries and frameworks?
12:59
Codecademy
Рет қаралды 106 М.
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 5 МЛН
GamePad İle Bisiklet Yönetmek #shorts
0:26
Osman Kabadayı
Рет қаралды 572 М.
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 8 МЛН
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,2 МЛН
Самый дорогой кабель Apple
0:37
Romancev768
Рет қаралды 178 М.
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 18 МЛН