Working with Libraries

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey there, Cybrarians,
00:00
and welcome back to the Linux Plus
00:00
>> course here at Cybrary.
00:00
>> I'm your instructor, Rob Gills,
00:00
and in today's lesson,
00:00
we're going to cover working with libraries.
00:00
Upon completion of today's lesson,
00:00
you're going to be able to understand
00:00
>> how Linux uses library files
00:00
>> and shared libraries,
00:00
>> and we'll also see how to use
00:00
the ldd and ldconfig commands.
00:00
In the previous lesson,
00:00
>> we talked about the C compiler,
00:00
>> and the C programming languages
00:00
>> uses this concept of library files
00:00
>> which are shared between applications.
00:00
>> Applications use these to access common functions.
00:00
In other words, developers don't have
00:00
>> to constantly reinvent the wheel
00:00
>> by writing functions that already exist
00:00
>> out there on the system.
00:00
>> They can access these in
00:00
library files and shared libraries.
00:00
Now, historically, programs would use a static library.
00:00
That would be a library that's
00:00
specific to a programmer version.
00:00
Static libraries had the.a suffix or extension,
00:00
but these are now deprecated
00:00
>> by something called dynamic shared libraries.
00:00
>> Now, dynamic shared libraries
00:00
>> have a.so suffix by comparison.
00:00
>> SO stands for shared object.
00:00
This is just used by developers and their code,
00:00
and these functions are called at runtime.
00:00
But if that shared library
00:00
isn't on the system when it's called,
00:00
the application can throw an error or a crash.
00:00
Now, how do you make sure that
00:00
libraries exist and applications don't crash?
00:00
How do you track down libraries?
00:00
Well, you use something called the ldd command.
00:00
The ldd command is used to find the libraries
00:00
>> that are required for that program to run,
00:00
>> and you could just do ldd,
00:00
>> and then the full path to the programming.
00:00
>> For example, we can do ldd user/bin/diff,
00:00
>> because that is the full and absolute
00:00
>> path to the diff command,
00:00
>> and that will tell us about all the libraries
00:00
>> that diff needs in order to run.
00:00
>> Library files themselves
00:00
>> are stored in a few places,
00:00
>> generally, lib or user lib
00:00
>> or lib 64 or user lib 64,
00:00
>> and it's becoming increasingly common.
00:00
These are just pointers,
00:00
user lib or user lib 64 is just a pointer
00:00
to lib 64 or vice versa.
00:00
Paths to library files are found at seldso.com
00:00
>> or in the duct directory at scdslo.conf.d,
00:00
>> or sometimes they'll actually be found
00:00
>> in a path and environmental variable
00:00
>> called lb_library_path.
00:00
>> Now, this brings the question,
00:00
how does an application actually
00:00
find a specific shared library?
00:00
Well, the application can call something
00:00
>> called the dynamic linker or ldso,
00:00
>> and that is aware of all the shared libraries
00:00
>> that exist in a system.
00:00
>> It basically is like a librarian who knows
00:00
>> where to find books in the library.
00:00
>> It lowers the libraries that
00:00
need to be run for the application.
00:00
But what happens if he can't find a library?
00:00
What happens?
00:00
>> Well, not all hope is lost.
00:00
>> You can still run the ldconfig command,
00:00
and ldconfig Command is what is used
00:00
>> to build the ld.so.cache file used by ldso,
00:00
>> used by what the applications
00:00
call when they're looking for a library.
00:00
This file, the ldso.cache,
00:00
is used by the dynamic linker,
00:00
the library and to find your libraries,
00:00
and so rerunning that command
00:00
>> is going to refresh the library list,
00:00
>> and then if that doesn't work,
00:00
then you have to play library
00:00
>> on which no one's favorite game
00:00
>> by using the ldd command.
00:00
>> But with that, in this lesson,
00:00
we covered the concepts
00:00
>> of library files and shared libraries in Linux,
00:00
>> and also the ldd and ldconfig commands.
Up Next