I've got two source files in two directories:
Common/common.d
module common;
import std.stdio;
int main(string[] args)
{
Foo foo = cast(Foo)Object.factory("special.Bar");
foo.do_something();
return 0;
}
abstract class Foo {
abstract void do_something();
}
Special/special.d
module special;
import std.stdio;
import common;
class Bar : Foo {
override void do_something()
{
writeln("works");
}
}
Now I try to run it with rdmd and dmd and get quite different
results:
$> rdmd -ICommon Special/special.d
works
$> dmd -ICommon Special/special.d
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function
`_start':
(.text+0x20): undefined reference to `main'
special.o:(.data.rel.ro+0x18): undefined reference to
`_D6common12__ModuleInfoZ'
special.o:(.data._D7special3Bar7__ClassZ+0x50): undefined
reference to `_D6common3Foo7__ClassZ'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
I encountered this, when I was curious if I can move the main
function to a diffent module, because it will be the same in
several modules anyway. When testing with rdmd, everything
worked. Later, I found out, that with dmd it doesn't. (And with
gdc and ldc2 it doesn't work too.)
For me, this looks like a bug in either rdmd or dmd. But maybe
there is something about it that I do not understand.