HomeОбразованиеRelated VideosMore From: theurbanpenguin

Linux Understanding Shared Libraries

304 ratings | 27923 views
More videos like this online at http://www.theurbanpenguin.com If you need a little help understanding standard libraries ir shared modules in Linux then here we work with the Raspberry Pi and Raspbian Linux to show you how. We create a .so file from scratch and use it withing a program we link to the library. You will see ldd and ldconfig as well as the gcc options needed to make this work
Html code for embedding videos on your blog
Text Comments (28)
donnlee (7 days ago)
Excellent tutorial. Example is clear, focused and scenario is practical. Well done!
theurbanpenguin (4 days ago)
Thx
zTioLuh ✓ (2 months ago)
Does anyone know how to compile folders and files (more than one) in .so format?
Enitin (2 months ago)
You are not explaining what those parameters are.
Stav7 (4 months ago)
so we dont need something like a .lib file? like you would on windows? simply a .so is everything? also if we end up specifying the path to the lib with -L<path_to_lib> when we compile at the end then why do we need to bother with all the config nonsens in the first place?
Stav7 (4 months ago)
ohh nevermind i get it. i didn't watch the very last bit of the video.
Dan Conway (4 months ago)
This will normally need the inclusion of.. pedophiles? Lol had to rewind that
Hermish Zen (5 months ago)
Are you Scottish? You have that beautiful accent :D
Matthijs Veldhoven (7 months ago)
Why is unistd.h included in standard.c? It is not used... I redid the tutorial with the following code files below. Advantage is that the main function and its module do not have to know any details about the implementation of the functions/methods in the shared object; just including the header file displayuid.h is enough. compile.sh ========== #!/bin/sh command() { echo "`date` Starting: $*" $* echo "`date` Finished: $*" echo "Press enter to continue" read DUMMY } ## command \rm *.o *.so command gcc -c -fPIC displayuid.c -Wall command gcc -shared -o libdisplayuid.so displayuid.o -Wall command sudo cp libdisplayuid.so /usr/local/lib/tmp_lib_maot command gcc -L /usr/local/lib/tmp_lib_maot/ standard.c -o standard.o -l displayuid -Wall command standard.o displayuid.c ============ #include <stdio.h> #include <unistd.h> #include "displayuid.h" void display_uid() { int realUid = getuid(); int euid = geteuid(); printf("The real UID= %d\n", realUid); printf("The effective UID= %d\n", euid); } displayuid.h ============ #ifndef DISPLAYUID_H #define DISPLAYUID_H void display_uid(); #endif // DISPLAYUID_H standard.c ========== #include <stdio.h> #include "displayuid.h" int main() { printf("This is the main program\n"); display_uid(); return 0; }
Srinesh Nisala (1 year ago)
This is a awesome video. wondered what the heck is Linux shared library and decide to youtube that.
bc10000 (1 year ago)
speed of 1.25 really helps guys
No Fullname (9 months ago)
omg, yes!
Anirban Saha (1 year ago)
But while compiling displayuid.c , there should be compilation errors for the undeclared functions getuid() and geteuid() ?
Błażej Michalik (1 year ago)
Not really. C compilers won't complain, when there is an undefined reference. To be exact, there always are at the stage of compiling. Header files are just there to tell the compiler: "hey, yes, those functions, those will be added later, don't worry about them, just remember that those names aren't mistakes, and don't complain when you see them, good boy". Complaining about unresolved references is the job of linker. That's why, when you are using gcc from command line, you have to tell it where every single file of your code is. Gcc has no information about their location, nor does header files or any part of your code. In this case, you will be compiling this code to a single object file, then it's a job of the linker that will link it with your program later, to resolve the references.
Jixuan Cheng (1 year ago)
so helpful. Thank you very much
Ramon Blanquer (1 year ago)
Thank you very much!
wickedcat (2 years ago)
Great ! Apparently, it looks different from Windows DLLs,... is it possible to put a .so near the program like in Windows (.exe and .dll in the same directory) ?
Arsalan Shaikh (2 years ago)
I did one blunder today and need to ask a question: I mistakenly deleted some lib files `zypper remove lib *` now zypper command was not working :) how could I restore all missed? Thanks, Tech newbie.
sushil lakra (3 years ago)
I would like to understand how shared libraries work. Basically, how symbols are found and referred.
Jaroslav Malec (3 years ago)
Thanks! I learned that C allowed "implicit declaration of functions" prior to C99. I'm a C++ person, so the fact that you can get away with using an undeclared symbol. I understand you ommited the whole "header/prototype thing" for clarity, but perhaps you could have mentioned that. If you did, I'm sorry, I missed that.
Robert Klein (3 years ago)
Very nice video man!
heybrohigh5 (4 years ago)
Very informative.  Thanks!
Dartht33bagger (4 years ago)
I'm going to sit down and give this a try tomorrow.  I'm taking a Linux device drivers class right now it has sparked my interest on topics like this.  Thanks for the video!
Henry Hallam (4 years ago)
You really should have included <stdio.h> in displayuid.c.  That warning was important and you didn't explain it correctly.
Gfast Gao (9 months ago)
You're perhapse right. But can you just make a small quick vid like he doese? It would be very very helpful!
Srinesh Nisala (1 year ago)
but the program runs normally. is it necessary to put stdio in the library? can you explain?
partyboycpt (4 years ago)
you cannot dislike this!
theurbanpenguin (4 years ago)
You have to create a shared library to truly understand them

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.