Can gcc and Linux create a dynamic library?

Ian Lance Taylor iant@google.com
Wed Dec 22 16:48:00 GMT 2010


ali hagigat <hagigatali@gmail.com> writes:

> My question is about dynamic libraries and shared libraries in Linux
> and their differences.
>
> Is it possible to create a dynamic library by gcc?

Yes.

> Is my following understanding from a dynamic library OK?
>
> I think a dynamic library is added to the address space of a running
> code in run time.
> If program A uses a dynamic library and in run time A references a
> variable(not inside the code of A), then the code of that library is
> added to the address space of A.

Sort of but misleading.

> If another program B has been linked with the same library dynamically
> and B references a variable (not inside the code of B), then the code
> of that library is added to the address space of B too.

Sort of but misleading.

> This concept is different with a shared library which its code is put
> into the memory only once and many programs use it.  Is that right?

Yes.

Your understanding is misleading because when you link the program it
gets a list of the dynamic libraries that it requires.  When the program
starts up, the dynamic linker finds those dynamic libraries and adds
them to the address space.  That is, the dynamic library is not added
when the variable is referenced.  It is added when the program starts
running.

There is also dlopen, which does happen at runtime, but via explicit
action, not via a reference to a variable.

Ian



More information about the Binutils mailing list