dmd vs rdmd

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 10 14:50:37 PDT 2011


On 2011-06-10 14:28, Joshua Niehus wrote:
> Hello,
> 
> I am trying to compile code which is composed of two modules (in the same
> directory):
> 
> main.d
> foo.d
> 
> foo.d just declares a class Foo which has a string variable "bar" which i
> set to "hello" and main.d just prints bar's value to the console:
> 
> // --------- main.d -----------
> import std.stdio, foo;
> 
> void main() {
> Foo f = new Foo;
> writeln(f.bar);
> }
> 
> When i attempt to compile main.d via:
> $dmd main.d
> I get undefined symbol errors.
> 
> But when I run:
> $rdmd main.d
> it works as expected.
> 
> The only way I could get main.d to compile with just dmd was to compile foo
> as a lib first and then compile main.d and passing the foo.a file as an
> argument:
> $dmd -lib foo.d
> $dmd main.d foo.a
> 
> Is this normal?
> I got the impression from TDPL (Alexandrescu) that the dmd compiler would
> automatically search the root directory, find foo.d, work its magic, and
> create all the symbols that were defined in foo.d for main.d to compile...

With dmd, you must list every file that you're compiling. The only exceptions 
are that when dealing with libraries, dmd to have the root directory where the 
source is passed to -I, and it needs to have the root directory where the 
library is given with -L and -l with the library name (or just the library 
directly if you don't want it to search for the library). It's like gcc and 
dmc in that respect. It does nothing extra to track down files to compile for 
you. It'll find the source for importing thanks to -I, but it won't compile 
it. You must still compile it. You don't normally need -I or -L however, 
because dmd.conf (or sc.ini on Windows) already adds the appropriate flags for 
Phobos for you. You only need too specify them yourself when using other 
libraries.

rdmd does extra magic to automatically track down all of the files that main.d 
imports and compile them. dmd doesn't do that.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list