Write Better Code! | How to Create Shared Libraries in C/C++

  Рет қаралды 52,126

Low Level Learning

Low Level Learning

3 жыл бұрын

In this video we talk about how to program our own custom libraries in C. We go deep on the process of implementing and creating shared libraries. Specifically, you will learn what shared libraries are, the benefits of creating your code as a shared library, and how program your own custom library.
Subscribe for more videos on low level computer topics!
Join us on Discord! / discord

Пікірлер: 62
@catsby9051
@catsby9051 2 ай бұрын
Statically linking libraries is, more often than not, the right way to go. In theory, shared libraries are nice but in practice, not a lot of sharing can actually take place. To ensure better portability, most developers will distribute the necessary shared libraries along with their application because they cannot be sure that the system that the app is installed on will have the necessary versions of the shared libraries. This fact nullifies the arguments around disk and RAM usage. In the case of containers, the entire file system is shipped with the application. Including all shared libraries.
@makara2711
@makara2711 3 жыл бұрын
i hope you do more C videos, particularly ones involving pointers on structures, unions, or arrays
@darren15
@darren15 Жыл бұрын
Awesome video. I had wondered for years how shared libraries worked. Thanks alot.
@delqyrus2619
@delqyrus2619 Жыл бұрын
Thanks! I knew how to write libraries, but i never completely understood what is happening under the hood. Now i understand at least more!
@bbug705076
@bbug705076 2 жыл бұрын
Thanks for the content. I did benefit from this channel
@Stevesteacher
@Stevesteacher Жыл бұрын
Thank you, I've been struggling with this for a while!
@nikhilsha4551
@nikhilsha4551 Жыл бұрын
Shared libraries are very useful, especially when implementing Python in C!
@a.v7998
@a.v7998 2 ай бұрын
Awesome video man!!
@AndrewMelnychuk0seen
@AndrewMelnychuk0seen Жыл бұрын
This was so good! Thanks!
@cd-stephen
@cd-stephen Жыл бұрын
i learn so much here - thank you for your channel
@user-nr4dx9ne4g
@user-nr4dx9ne4g 7 ай бұрын
Thank you for this useful video!
@renichbon
@renichbon Жыл бұрын
Pretty good content, man. Keep it up.
@LowLevelLearning
@LowLevelLearning Жыл бұрын
Appreciate it!
@charliebanales5287
@charliebanales5287 2 жыл бұрын
Your videos are awesome, thank you so much!
@LowLevelLearning
@LowLevelLearning 2 жыл бұрын
Glad you like them!
@jonathanmoore5619
@jonathanmoore5619 3 жыл бұрын
Just found you. Great expo.
@eng.shh80
@eng.shh80 2 жыл бұрын
Great , thank you!
@LowLevelLearning
@LowLevelLearning 2 жыл бұрын
You are welcome!
@alfajrdream
@alfajrdream Жыл бұрын
Very nice !!
@alexandrohdez3982
@alexandrohdez3982 Жыл бұрын
you are the best 👏👏👏...
@empajerek4193
@empajerek4193 3 жыл бұрын
Great!!!
@meenamurthy1503
@meenamurthy1503 Жыл бұрын
Thank you!
@colydeane
@colydeane 3 жыл бұрын
Nice explanation.
@LowLevelLearning
@LowLevelLearning 3 жыл бұрын
Glad it was helpful!
@CHEL0VEK100
@CHEL0VEK100 3 ай бұрын
It was a good video, thanks! Do you have a video about static libraries? ❤
@epocfeal
@epocfeal 2 жыл бұрын
thank you!
@xarax7950
@xarax7950 Ай бұрын
thanks !
@mage0966
@mage0966 2 жыл бұрын
Great video, i found it very interesting, but there are too many concepts for just one video, i hope that you could make another video or course for explain this concepts more deppeer.
@believeinpractical3930
@believeinpractical3930 3 жыл бұрын
Awesome
@acommunistdwarf
@acommunistdwarf Жыл бұрын
Can you selectively load them in the program or does the selection of the library that provides the functions have to be done at compile time?
@Speykious
@Speykious 2 жыл бұрын
Fun fact ─ related to shared libraries, but not quite C: Rust, as nice of a language as it is, doesn't link its standard library dynamically. Meaning that each time you do any kind of executable, it takes at least 3 MB of space from the get go because Rust's standard library has been appended. There is still a -prefer-dynamic compiler flag, but it is statically linked by default. I'm not informed enough to know why it's like that. Maybe in the future it will become mature enough to prefer dynamic by default, because that would definitely optimize a lot of space, given how much programs are being written in Rust these days.
@honkhonk8009
@honkhonk8009 2 жыл бұрын
I think its because with most programs to just get stuff up and running, you dont really care much about optimization. that stuff comes last yk. Cleaning up your source and optimizations come after u have a working product.
@Speykious
@Speykious 2 жыл бұрын
@@honkhonk8009 Programming optimizations are separate from static/dynamic linking. Lots of people have been telling me however that the actual reason this is the case is because the Rust ABI (Application Binary Interface) is not stable, and that having a stable ABI would severely restrain the ability of the language to be changed, which goes against the goals of the core team. I did ask myself if it would be possible for Rust to ever become stable enough for the ABI to be as stable, though I know nothing about ABIs unfortunately
@JohannY2
@JohannY2 2 жыл бұрын
I would suggest that you zoom in more, for those of us that watch on phones.
@1873Winchester
@1873Winchester Жыл бұрын
It feels a bit clumsy but I suppose that is to explain it better what is happening. But in a production environment I assume it's done so that the end user who will run the program, doesn't need to include the library path every time? Perhaps the library is installed in the default library path by an installer?
@autistadolinux5336
@autistadolinux5336 Жыл бұрын
There's a way to change that path for each executable, as far as i know, and desktop entries (icons) usually also include a LD_LIBRARY_PATH at execution. But for most of the time its completely useless to have an shared library, unless you want to preserve the same functionality across the whole system (libc's are a good example of this) or you want to make some sort of plugin system (GIMP and Xfce panel plugins are a good example of this).
@brecoldyls
@brecoldyls 2 жыл бұрын
Great video! When linking, is it always necessary to set the LD_LIBRARY_PATH environment variable? I was able to link and run a test program without doing so, and I'm wondering what the general conditions are for needing to vs not needing to set it
@_denzy_6310
@_denzy_6310 2 жыл бұрын
Linker will set a static location where the so is located. If it changes, you get so not found. Check with 'ldd' command
@nettoaoquadrado
@nettoaoquadrado Жыл бұрын
Fico muito grato por ter acesso a um conteúdo de qualidade de maneira totalmente gratuita. Obrigado de coração
@ajayjadhav900
@ajayjadhav900 2 жыл бұрын
How to include sub-directories in Visual Studio? I have to include many header files, which are in different sub-directories. Is there a way in Visual Studio (I am using 2013 edition) to set one include path that Visual Studio will search also the sub-directories for header files? My Project is in C/C++. Add the "base folder" to the project (project properties -> Configuration Properties -> C/C++ -> Additional Include Directories, "additional include directories") I have tried the above option but it is not possible for me to add each and every directory followed by a semicolon. I have total 60 + different C C++ sub-directories
@erdican7749
@erdican7749 2 жыл бұрын
Actualy it includes everyhing at that path to your include path so you could include like this: #include "folder/header.h"
@kevinshao9148
@kevinshao9148 Жыл бұрын
Thanks for the great video! 2 questions would like to confirm: 1) so from your video, this .so library will be linked at run time, not pre-compiled in the executable main, right? 2) and you don't need to include this shared object library? but you have to put declaration? Thanks a lot!
@thediaclub4781
@thediaclub4781 Жыл бұрын
2) The declarations are necessary but often put into header files. Like printf probably is declared somewhere in stdio.h
@kevinshao9148
@kevinshao9148 Жыл бұрын
@@thediaclub4781 Thanks a lot for kind reply!!!
@PurpleMenace297
@PurpleMenace297 4 ай бұрын
I have two questions. 1. At 11:45 -L is specified during the gcc command to "let the linker know where to find the shared library". But regardless you still need to set the envvar LD_LIBRARY_PATH. is this because the linker and loader are not the same? 2. During the compilation of the shared library you specified fpic to "make it address independent" what are the consequences of not specifying this? And similarly why exactly do we need to specify this?
@LeaoMartelo
@LeaoMartelo Ай бұрын
hello i know this is 2 months ago, but i think i can reply to the second question in a simplified way not making it address independent will make it look for the same addresses in ram every time, that might not work depending on your program, using that flag makes it set the address table at link time for the program
@alexobzor
@alexobzor Жыл бұрын
If you hadn't declared these functions in main.c, would it succeeded? I think that it wasn't necessary, but I don't know exactly.
@virtualouise
@virtualouise Жыл бұрын
Generally they would be in some header file that you have to declare in your main.c
@peterjansen4826
@peterjansen4826 Жыл бұрын
You probably don't read this given that it is a 2 years old video. The -lmmath part at 11m38s is confusing. The name of the library is mmath. If you use an option (-l) then usually you would have a space after it to give the string but you typed it without a space and it works.
@acommunistdwarf
@acommunistdwarf Жыл бұрын
It's how GCC works, that's why the library has to be named starting with lib.
@kelseystickney8663
@kelseystickney8663 7 ай бұрын
You misspelled “maintenance”. Didn’t know if you realized that 3 years after the fact. Haha
@bbug705076
@bbug705076 2 жыл бұрын
!
@houseisforthesoul
@houseisforthesoul Жыл бұрын
can i have some
@uzumakiuchiha7678
@uzumakiuchiha7678 Жыл бұрын
DWM?
@henryg2350
@henryg2350 Жыл бұрын
Sob, I can’t watch damn videos with loud ass keyboards … they cringe me so hard idk why… but can you show give a link to the info you explained might be??
@sj82516
@sj82516 9 ай бұрын
Thanks for the good content! Just wondering why you name your shared object as `libmy_math.so` but the linker are finding `libmmath.so` ? How the naming match to each other ?
@xeniaxu4452
@xeniaxu4452 4 ай бұрын
In my macbook, after I renamed the libmy_math into libmmath, the linker can't work, it still looked for libmy_math obj but not libmmath
@mytechnotalent
@mytechnotalent 3 жыл бұрын
Great vid! How would we do this for the Pico? I was able to get the lib created with arm-none-eabi-gcc -o libtest.so -fpic -shared -s test.c ? What would have to be done in the CMakeLists.txt file?
@LowLevelLearning
@LowLevelLearning 3 жыл бұрын
The problem is that the Pico only takes one file as input and doesn't do runtime linking. You could link your library into your program at compile time by producing archive files (libtest.a instead of libtest.so). Then your CMakeLists file would pull them in to the UF2 file.
Haha😂 Power💪 #trending #funny #viral #shorts
00:18
Reaction Station TV
Рет қаралды 16 МЛН
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Гараж 54
Рет қаралды 14 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 6 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
How LLVM & Clang work
34:29
tanmay bakshi
Рет қаралды 55 М.
everything is open source if you can reverse engineer (try it RIGHT NOW!)
13:56
Low Level Learning
Рет қаралды 1,3 МЛН
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel
Рет қаралды 92 М.
Static and Dynamic Linking on Linux with gcc
27:09
embeddedarmdev
Рет қаралды 44 М.
#BB11 Create an Arduino Library😨 - A Real World Example (Easy)
25:54
Static vs. Shared Libraries
11:00
Dave Xiang
Рет қаралды 64 М.
every good programmer should know how to code this data structure (its easy)
21:08
Go isn’t secure?!? feat. Low Level Learning | 053
51:14
Backend Banter
Рет қаралды 37 М.
How to write your own code libraries in C.
9:57
Jacob Sorber
Рет қаралды 135 М.
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 6 МЛН
Самый дорогой кабель Apple
0:37
Romancev768
Рет қаралды 233 М.
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,2 МЛН
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 3,6 МЛН
Clicks чехол-клавиатура для iPhone ⌨️
0:59