bindbc, SDL
Mike Parker
aldacron at gmail.com
Thu Mar 27 14:48:15 UTC 2025
On Thursday, 27 March 2025 at 14:10:21 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> The bindbc family of packages, usually can link against a
> shared library both during compilation (statically), or during
> runtime (dynamically).
>
> The import library serves no purpose if you are linking
> dynamically.
Let's get our terminology straight here.
BindBC supports static bindings and dynamic bindings.
Static bindings are used for both static and dynamic linking,
i.e., there is a link-time dependency. Static linking means
linking to the static library and there is no runtime dependency.
Dynamic linking means linking with the import library on Windows
and the dynamic library on other platforms, in which case there's
a runtime dependency on the shared library.
Dynamic bindings are used for *dynamic loading*, not dynamic
linking. This means there is no link-time dependency, but there
is still a runtime dependency on the shared library. In this
case, the shared library must be loaded manually at runtime.
In a static binding, the C function are declared as normal
function declarations. When statically linking, the linker
matches the symbols up. When dynamically linking, the system
loader loads the shared library and then matches the symbols up.
In a dynamic binding, the C functions are declared as function
pointers. The programmer must get a handle to the shared library
via a system API call, then use the handle to fetch a pointer to
each of the library's functions (or just the ones needed) and
assign them to the function pointers declared by the binding.
That's what bindbc-loader does, and why functions like `loadSDL`
need to be called first when using the dynamic binding.
More information about the Digitalmars-d-learn
mailing list