N
The Daily Insight

What is a shared object library?

Author

Christopher Harper

Updated on March 29, 2026

Shared Object: A library that is automatically linked into a program when the program starts, and exists as a standalone file. The library is included in the linking list at compile time (ie: LDOPTS+=-lmylib for a library file named mylib.so ).

Is iostream a header file or library?

C++ input/output streams are primarily defined by iostream , a header file that is part of the C++ standard library (the name stands for Input/Output Stream).

Where is the iostream library located?

If your compiler installation is sane you should never have to add the directory containing the standard library headers to your include directories — the compiler already knows best where to look. On my Windows box, iostream (now without . h ) is at :\cygwin\lib\gcc\i686-pc-cygwin\4.5.

How do I create a shared object library?

There are four steps:

  1. Compile C++ library code to object file (using g++)
  2. Create shared library file (. SO) using gcc –shared.
  3. Compile the C++ code using the header library file using the shared library (using g++)
  4. Set LD_LIBRARY_PATH.
  5. Run the executable (using a. out)
  6. Step 1: Compile C code to object file.

How does shared library work?

Simply put, A shared library/ Dynamic Library is a library that is loaded dynamically at runtime for each application that requires it. They load only a single copy of the library file in memory when you run a program, so a lot of memory is saved when you start running multiple programs using that library.

What is shared object so )?

A shared object is an indivisible unit that is generated from one or more relocatable objects. Shared objects can be bound with dynamic executables to form a runable process. As their name implies, shared objects can be shared by more than one application.

What is iostream library?

The iostream library is an object-oriented library that provides input and output functionality using streams. A stream is an abstraction that represents a device on which input and ouput operations are performed. A stream can basically be represented as a source or destination of characters of indefinite length.

Where does GCC Look for shared libraries?

It looks in the default directories /lib then /usr/lib (disabled with the -z nodeflib linker option).

  • What is position independent code?
  • GCC first searches for libraries in /usr/local/lib, then in /usr/lib.
  • The default GNU loader, ld.so, looks for libraries in the following order: ↩

What is the purpose of using shared libraries?

Shared Libraries are the libraries that can be linked to any program at run-time. They provide a means to use code that can be loaded anywhere in the memory. Once loaded, the shared library code can be used by any number of programs.

What are shared objects?

What is iostream in C++?

The iostreamlibrary provides protection against multiple threads that attempt to modify the state of objects (that is, instances of a C++ class) shared by more than one thread. However, the scope of MT-safety for an iostreamobject is confined to the period in which the object’s public member function is executing.

Are iostream functions reentrant?

Generally, this “correctness” means that all of its public functions are reentrant. The iostreamlibrary provides protection against multiple threads that attempt to modify the state of objects (that is, instances of a C++ class) shared by more than one thread.

What is an ostream object?

An ostream object. The object controls buffered insertions to the standard error output as a byte stream. See cerr for an example of using clog. Specifies the cout global stream. An ostream object. The object controls insertions to the standard output as a byte stream. See cerr for an example of using cout.

How do I create a shared library in G++?

This uses the linker program (ld), usually called by g++ (remember we told g++ with the -c option not to link in the first stage). It says make a shared object (the -shared option), using the input file pal.o and call it libpal.so (the -o option). The .so extension is the usual naming convention for shared libraries.