Тёмный

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

Low Level
Подписаться 692 тыс.
Просмотров 56 тыс.
50% 1

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

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 65   
@hetaeramancer
@hetaeramancer 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
@catsby9051
@catsby9051 5 месяцев назад
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.
@AllanAlmeidaOficial
@AllanAlmeidaOficial 2 месяца назад
Thank you so much for this video, very well explained and putting into practice really made the difference! 🎉
@nikhilsha4551
@nikhilsha4551 Год назад
Shared libraries are very useful, especially when implementing Python in C!
@renichbon
@renichbon 2 года назад
Pretty good content, man. Keep it up.
@LowLevel-TV
@LowLevel-TV 2 года назад
Appreciate it!
@Stevesteacher
@Stevesteacher 2 года назад
Thank you, I've been struggling with this for a while!
@charliebanales5287
@charliebanales5287 2 года назад
Your videos are awesome, thank you so much!
@LowLevel-TV
@LowLevel-TV 2 года назад
Glad you like them!
@leocode128
@leocode128 9 дней назад
Hi , it will be really great if you make a video on complete compile process for c or cpp , like what does the -i flag does , whats pkg-config what is linking, how to create a linker script for embedded programming etc . Its very hard to find resources explaining all these and i really want to know the ins and outs
@Speykious
@Speykious 3 года назад
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
@cd-stephen
@cd-stephen Год назад
i learn so much here - thank you for your channel
@colydeane
@colydeane 3 года назад
Nice explanation.
@LowLevel-TV
@LowLevel-TV 3 года назад
Glad it was helpful!
@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).
@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.
@eng.shh80
@eng.shh80 2 года назад
Great , thank you!
@LowLevel-TV
@LowLevel-TV 2 года назад
You are welcome!
@CHEL0VEK100
@CHEL0VEK100 6 месяцев назад
It was a good video, thanks! Do you have a video about static libraries? ❤
@JohannY2
@JohannY2 2 года назад
I would suggest that you zoom in more, for those of us that watch on phones.
@MohammadHabash-b7r
@MohammadHabash-b7r 10 месяцев назад
Thank you for this useful video!
@a.v7998
@a.v7998 4 месяца назад
Awesome video man!!
@AndrewMelnychuk0seen
@AndrewMelnychuk0seen 2 года назад
This was so good! Thanks!
@alexandrohdez3982
@alexandrohdez3982 Год назад
you are the best 👏👏👏...
@PurpleMenace297
@PurpleMenace297 7 месяцев назад
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 4 месяца назад
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
@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.
@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
@empajerek4193
@empajerek4193 3 года назад
Great!!!
@xarax7950
@xarax7950 3 месяца назад
thanks !
@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"
@meenamurthy1503
@meenamurthy1503 2 года назад
Thank you!
@jonathanmoore5619
@jonathanmoore5619 3 года назад
Just found you. Great expo.
@believeinpractical3930
@believeinpractical3930 3 года назад
Awesome
@alfajrdream
@alfajrdream 2 года назад
Very nice !!
@epocfeal
@epocfeal 2 года назад
thank you!
@kevinshao9148
@kevinshao9148 2 года назад
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!!!
@kelseystickney8663
@kelseystickney8663 10 месяцев назад
You misspelled “maintenance”. Didn’t know if you realized that 3 years after the fact. Haha
@alexobzor
@alexobzor 2 года назад
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
@nettoaoquadrado
@nettoaoquadrado Год назад
Fico muito grato por ter acesso a um conteúdo de qualidade de maneira totalmente gratuita. Obrigado de coração
@bbug705076
@bbug705076 2 года назад
!
@houseisforthesoul
@houseisforthesoul Год назад
can i have some
@uzumakiuchiha7678
@uzumakiuchiha7678 Год назад
DWM?
@poutineausyropderable7108
@poutineausyropderable7108 Месяц назад
I see you are not a ricer. Base I3.
@sj82516
@sj82516 11 месяцев назад
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 7 месяцев назад
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?
@LowLevel-TV
@LowLevel-TV 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.
@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??
@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?
Далее
Static and Dynamic Linking on Linux with gcc
27:09
Просмотров 46 тыс.
we need to talk about the new Linux exploit (9.9 CVSS)
13:50
how NASA writes space-proof code
6:03
Просмотров 2,2 млн
Static vs. Shared Libraries
11:00
Просмотров 65 тыс.
why do header files even exist?
10:53
Просмотров 408 тыс.
How to write your own code libraries in C.
9:57
Просмотров 140 тыс.
how Google writes gorgeous C++
7:40
Просмотров 886 тыс.
How LLVM & Clang work
34:29
Просмотров 57 тыс.