What if other libraries that are not GBLIC related happen to use those names for their exported functions?
the technical term for this situation is a "clusterf**k". while there is no hard mechanism or rule preventing multiple libraries containing a function/symbol with the same name, doing so severely breaks linux. the glibc authors are well aware of this and warn against ever duplicating any function names across different libraries.
an example that flies oh-so-close-to breaking this warning is the function
fnmatch, which exists in glibc and also sort-of-exists (or once existed) in gtk. the code to get around this conflict in FPC is icky.
not preventing the use of duplicate function names seems to be a fundamental design flaw in linux (and other unix'es). the use of versioned symbols (eg, dlopen@GLIBC_2.2.5) gets around it by appending a library-specific suffix, but as we have seen introduces a whole new layer of suffering in exchange.
in FPC the actual breaking occurs when you use
external to access a library function; the
function name is referenced in the ELF header's Dynamic Symbol Table, while the
library name is referenced in a 'DT_NEEDED' section that can be found by grepping the output of readelf -a for '(NEEDED)' . the kicker here is that, as far as i can determine,
no linkage is recorded between the
function name and the
library name specified as parameters to
external. put simply, the first occurrence of the function name that is found
anywhere at run-time is linked to by
ld, the loader.
this in itself is good enough reason why
external should be used sparingly and with extreme caution. an alternative mechanism using
dlopen et al exists that
does ties together function name and library name.
cheers,
rob :-)