x
Loading
 Loading
Hello, Guest | Login | Register

Building and Using Shared Libraries

Over the past several months, this column has shown you how to use gcc and g++ language extensions, how to link objects and functions, and how to build executables. We will continue this month with a discussion about a very specific type of object — a shared (or dynamic) library — and how to take advantage of it in your programs.

Over the past several months, this column has shown you how to use gcc and g++ language extensions, how to link objects and functions, and how to build executables. We will continue this month with a discussion about a very specific type of object — a shared (or dynamic) library — and how to take advantage of it in your programs.

A shared library is an object that has been specifically built to be loaded at runtime by some other application. In Microsoft Windows, they are called DLLs (dynamically linked libraries). On Linux, run /sbin/ldconfig -v as root to see all the shared libraries that applications make use of day in and day out.

The main advantage of using shared libraries is the potential for code reuse they provide. An example is the library that contains the printf() function. It’s safe to say that many (if not all) Linux utilities use this function. If it were impossible to load libraries dynamically, that function would have to be linked into every program that needed it, duplicating that piece of code all over your system. Obviously, this would consume disk space and make updates much more difficult. By using shared libraries, the printf() function can be stored in one library that is still available to any program that needs to use it.

Let’s assume that the printf() function was found to have a huge security hole. Without the benefit of shared libraries, every program that uses printf()

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace