Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically loading static library?

Can a static libary *.a in Linux be dynamically loaded at runtime?
I've read here that

...both static and shared libraries can be used as dynamically loaded libraries.

How to dynamically load static library?

like image 484
dragan.stepanovic Avatar asked Sep 02 '10 10:09

dragan.stepanovic


People also ask

Can static library use dynamic library?

There is nothing like “linking a static library to dynamic library”. “Linking” is a process of completing the “symbol table” present in every executable or a shared library (see “Linkers and symbol tables”).

What is a dynamic static library?

Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

How are static libraries loaded?

Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.

What is the difference between static library and DLL?

A static library must be linked into the final executable; it becomes part of the executable and follows it wherever it goes. A dynamic library is loaded every time the executable is executed and remains separate from the executable as a DLL file.


1 Answers

A static library is more or less just a collection of object files. If you want to use a static library in a program, you have to link the executable with it. The executable will then contain the static library (or the parts that you used).

If you want to load a static library at runtime using dlopen, you will have to first create a dynamic library libfoo.so containing it.

like image 180
JesperE Avatar answered Oct 22 '22 04:10

JesperE