You are on page 1of 6

User

Do you know windows DLL library ? Is it related to dynamic loading ?

Bing

Yes, a Windows DLL (Dynamic Link Library) is indeed related to dynamic


loading.

A DLL is a library that contains code and data that can be used by more than
one program at the same time12. For example, in Windows operating systems,
the Comdlg32 DLL performs common dialog box related functions. Each
program can use the functionality that is contained in this DLL to implement
an Open dialog box1. The use of DLLs helps promote modularization of code,
code reuse, efficient memory usage, and reduced disk space1.

Dynamic loading, on the other hand, is a mechanism by which a computer


program can, at run time, load a library (or other binary) into memory, retrieve
the addresses of functions and variables contained in the library, execute those
functions or access those variables, and unload the library from memory4. It is
one of the 3 mechanisms by which a computer program can use some other
software; the other two are static linking and dynamic linking 4.

So, in the context of a DLL, dynamic loading would allow a program to load
the DLL into memory at runtime, use its functions and data, and then unload it
when it's no longer needed. This allows for efficient use of resources and can
make programs more modular and adaptable.

Source(s)
1. Dynamic link library (DLL) - Windows Client | Microsoft Learn
2. Dynamic-Link Libraries (Dynamic-Link Libraries) - Win32 apps
3. Dynamic loading - Wikipedia
4. Create C/C++ DLLs in Visual Studio | Microsoft Learn
5. What is Dynamic Loading? (A Definitive Guide) - TWI
6. Difference between Static Loads and Dynamic Loads?

User

Is dynamic loading support in libraries other than DLL libraries ?

Bing
Yes, dynamic loading is supported in libraries other than DLLs. Dynamic
loading is a mechanism that is not exclusive to any particular type of library or
operating system. It's a general concept that can be implemented in various
ways depending on the system12.

For instance, in the context of C++, you can choose between dynamic (.dll, .so)
and static (.lib, .a) libraries1. Both types of libraries can support dynamic
loading, but they do so in different ways1.

On Linux systems, shared objects (.so) are the equivalent of DLLs on Windows4.
They can be loaded into the memory space of other programs, where the
functions can be executed and the data may be accessed 4. The Linux
Documentation Project also mentions dynamically loaded (DL) libraries, which
are libraries loaded at times other than during the startup of a program 3.

So, to answer your question, yes, dynamic loading is supported in libraries


other than DLL libraries. It's a versatile mechanism that can be used in various
contexts to load libraries into memory at runtime 1234.

Source(s)
1. c++ - When to use dynamic vs. static libraries - Stack Overflow
2. windows - Static vs. Dynamic Library Performance - Stack Overflow
3. Jack Whitham - Differences between dynamically linked libraries (.dll) and shared objects (.so)
4. Dynamically Loaded (DL) Libraries - Linux Documentation Project

User

As you mentioned above, what is the difference between shared objects ( .so )
and dynamically loaded (DL) libraries in Linux ?

Bing

Shared objects (.so) and dynamically loaded (DL) libraries in Linux are similar in
that they both contain executable code and data that can be loaded into the
memory space of other programs3. However, there are differences in how they
are used and loaded:

● Shared Objects (`.so`): These are automatically linked into a program


when the program starts12. The operating system loads the shared
library before the application starts2. They exist as standalone files and
are included in the linking list at compile time1. For example, if you have
a library file named mylib.so, it would be included at compile time like
this: LDOPTS+=-lmylib1.

● Dynamically Loaded (DL) Libraries: These libraries aren't automatically


loaded at program link time or start-up4. Instead, there is an API for
opening a library, looking up symbols, handling errors, and closing the
library4. In C, you would need to include the header file <dlfcn.h> to use
this API4. The library is not specified at compile-time, so it's not loaded
by the operating system2. Instead, your application will contain some
code to load the library2.

So, the main difference lies in the way these libraries are linked and loaded:
shared objects are linked at compile time and loaded at start-up by the
operating system, while DL libraries are loaded at runtime by the application
itself124.

Source(s)
1. Jack Whitham - Differences between dynamically linked libraries (.dll) and shared objects (.so)
2. Difference between shared objects (.so), static libraries (.a), and DLL's (.so)? - Stack Overflow
3. What is the difference between shared and dynamic libraries in C?
4. Dynamically Loaded (DL) Libraries - Linux Documentation Project

User

So you mean shared object (.so) doesn't support dynamic loading ?

Bing

No, that's not correct. Shared objects (.so) in Linux do support dynamic
loading. They can be loaded and unloaded at runtime, which is the essence of
dynamic loading.

The difference lies in how they are typically used. Shared objects are often
automatically loaded at program start-up by the operating system, but they
can also be dynamically loaded or unloaded at runtime if needed.

On the other hand, Dynamically Loaded (DL) libraries are specifically designed
to be loaded and unloaded at runtime, typically by the application itself.

So, both shared objects (.so) and DL libraries in Linux support dynamic
loading, but they are used in slightly different ways. I hope this clarifies the
matter for you. Let me know if you have any other questions! 😊
User

so you mean few people use shared objects (.so) to do dynamic loading ?

Bing

It's not necessarily that few people use shared objects (.so) for dynamic
loading. It's more about the specific needs of the application.

Shared objects (.so) are often used in situations where the library is a standard
component that will always be needed by the application. In these cases, the
operating system can load the library at startup, which is efficient and
convenient.

However, if an application needs to load a library based on certain conditions,


or if it needs to conserve resources by only loading libraries as needed, then
dynamic loading can be a better choice. This is often done using DL libraries,
but it can also be done with shared objects (.so).

So, it's not about the number of people using one method or the other, but
rather about choosing the right tool for the job based on the specific
requirements of the application. Both shared objects and DL libraries have
their uses, and both can be used for dynamic loading when appropriate. 😊

User

so you mean shared objects (.so) is more general then DL library ?

Bing

In a way, yes. Shared objects (.so) in Linux are a more general form of
dynamically loadable library. They can be used in a variety of ways, including
being loaded at startup by the operating system, or being dynamically loaded
and unloaded at runtime by an application.

Dynamically Loaded (DL) libraries, on the other hand, are typically used
specifically for dynamic loading at runtime. They provide an API for opening a
library, looking up symbols, handling errors, and closing the library.

So, while both shared objects and DL libraries can be used for dynamic
loading, shared objects have a broader range of uses, making them more
general in that sense. However, the choice between using shared objects or DL
libraries depends on the specific needs of the application. 😊
User

As you mentioned in your replies: "For instance, in the context of C++, you can
choose between dynamic (.dll, .so) and static (.lib, .a) libraries1. Both types of
libraries can support dynamic loading, but they do so in different ways." What
is the dynamic and static means here ? Dynamic inking or dynamic loading ?

Bing

In the context of libraries, "static" and "dynamic" can refer to both the linking
method (static linking or dynamic linking) and the loading method (static
loading or dynamic loading). Here's a brief explanation:

● Static Libraries (.lib, .a): In static linking, the linker copies all the
routines used in the program into the executable file12. This happens at
compile time2. The advantage is that the executable is self-contained
and can run independently without any other external dependencies 12.
However, the downside is that the executable file can be quite large and
any changes to the library would require the program to be re-linked
and re-compiled12.

● Dynamic Libraries (.dll, .so): In dynamic linking, the linker does not
copy the routines used in the program into the executable file 12. Instead,
a reference to the dynamic library is included in the executable 12. The
actual linking with the library routines does not occur until the
executable is run, which is why it's called "dynamic"12. This results in
smaller executable files and allows for the possibility of updating the
library routines without needing to link or compile the program again 12.

So, when we say "dynamic" or "static" in the context of libraries, we could be


referring to either the linking method (how the library is connected to the
program) or the loading method (when the library is loaded into memory). The
specific meaning depends on the context. I hope this helps clarify things! 😊

Source(s)
1. c++ - When to use dynamic vs. static libraries - Stack Overflow
2. Static and Dynamic Libraries | Set 1 - GeeksforGeeks
3. Difference Between Static Library And Dynamic Library
4. What is the difference between a static library and a dynamic one
5. The differences between a static library and a dynamic library
User

Is static libraries (.lib, .a) support dynamic loading ?

Bing

Static libraries (.lib, .a) are typically not used for dynamic loading. They are
linked at compile time, and the code from the library that the program uses is
included in the final executable12. This means that the library's code is always
present in the memory when the program runs12.

Dynamic loading, on the other hand, involves loading and unloading libraries
at runtime, which is typically done with dynamic libraries (.dll, .so) or
Dynamically Loaded (DL) libraries12.

While it's technically possible to dynamically load a static library, it's not
straightforward and requires additional steps1. For example, if you want to
load a static library at runtime using dlopen, you will have to first create a
dynamic library containing it1. So, in practice, dynamic loading is usually done
with dynamic libraries, not static libraries12.

I hope this answers your question! Let me know if you have any other
questions. 😊

Source(s)
1. c++ - dynamically loading static library? - Stack Overflow
2. c++ - When to use dynamic vs. static libraries - Stack Overflow
3. Static and Dynamic Libraries | Set 1 - GeeksforGeeks
4. static linking - Why cant you statically link dynamic libraries? - Stack Overflow

You might also like