Am 06.03.23 um 01:10 schrieb Frederick Virchanza Gotham:
Have you seen the comment below this message from 2018, that the dynamic
linker only respects weak symbols when you set LD_DYNAMIC_WEAK? Quoting
from the referenced page:
LD_DYNAMIC_WEAK (since glibc 2.1.91)
By default, when searching shared libraries to resolve a
symbol reference, the dynamic linker will resolve to the
first definition it finds.
Old glibc versions (before 2.2), provided a different
behavior: if the linker found a symbol that was weak, it
would remember that symbol and keep searching in the
remaining shared libraries. If it subsequently found a
strong definition of the same symbol, then it would
instead use that definition. (If no further symbol was
found, then the dynamic linker would use the weak symbol
that it initially found.)
The old glibc behavior was nonstandard. (Standard
practice is that the distinction between weak and strong
symbols should have effect only at static link time.) In
glibc 2.2, the dynamic linker was modified to provide the
current behavior (which was the behavior that was provided
by most other implementations at that time).
Defining the LD_DYNAMIC_WEAK environment variable (with
any value) provides the old (nonstandard) glibc behavior,
whereby a weak symbol in one shared library may be
overridden by a strong symbol subsequently discovered in
another shared library. (Note that even when this
variable is set, a strong symbol in a shared library will
not override a weak definition of the same symbol in the
main program.)
Since glibc 2.3.4, LD_DYNAMIC_WEAK is ignored in secure-
execution mode.
This sounds very hackish to me. Most portable (and easiest) solution
will be a shell script. The overall goal reminds me to the Tk toolkit.
In Tcl, you can do "package require Tk" which loads the Tk toolkit
dynamically. However, there are at least two files - Tk is its own
shared object, which depends on libX11 etc., while Tcl alone does not
depend on libX11. For a single file executable (called starpack) they go
through some hoops, especially attaching a load to the end of the
executable (similar to a self-extracting ZIP file), which is addressed
as a virtual file system. Are you sure it is worth to go through this
for your program? The simplest solution (besides a shell script) would
be to split the GUI part into its own library, which is installed as a
separate package.
Christian