"Johannes Pfau" wrote in message news:lrgar7$1vrr$1...@digitalmars.com...
Do you know if linkers actually guarantee that behaviour? AFAICS dmd
doesn't do anything special, it always emits weak symbols and just calls
gcc to link. The linker usually uses the first symbol it sees, but I
have not seen any guarantees for that.
Yes, they do. Or at least, it's the classic linker behaviour and I expect
they all implement it. It's relied upon for nofloat and a few other things.
It's one of the reasons linkers are hard to parallelize.
dmd does split single d modules into multiple object modules when compiling
with -lib, although I think that's fairly standard.
Also what happens if your main application doesn't use the template,
but two libraries use the same template. Then which instances are
actually used? I'd guess those from the 'first' library?
Well, the first one that it encounters after getting the undefined
reference.
eg
module application
{
undef x
...
}
lib1:
module a
{
undef tmpl
def a
}
module tmpl
{
def tmpl
}
lib2:
module x
{
undef tmpl
def x
}
module tmpl
{
def tmpl
}
Here nothing that the application references will cause the tmpl in lib1 to
get pulled in, but when it processes lib2 it will pull in x, and then tmpl.