Importing a module from another directory

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 27 10:10:00 PST 2014


On Saturday, 27 December 2014 at 18:01:19 UTC, Derix wrote:
> But of course ! I should have thought of this myself.
> Subsequent question though : what is the -I option for ? The dmd
> embedded help states
>
> -Ipath         where to look for imports
>
> so I'd naively think it would work too, but it yields the same
> error as above.

The error comes from the linker, the compiler itself found your 
imported module and compiled it without error.

In general, there are two ways in which you can compile a larger 
project consisting of multiple files. Either compile everything 
at once, as Adam suggests. In this case, the compiler will also 
call the linker for you to put all parts together and produce an 
executable.

The other way would be to compile each file (module) separately. 
To do so, you have to specify the `-c` option; the compiler will 
then write out an object file for the module you specified on the 
command line. When you're done compiling all modules, you need to 
invoke the linker manually, specifying all of the object files.

The latter is the default model used in C and C++. The reason is 
that during development it is often faster to recompile only 
those parts of your project that have actually changed (and those 
that depend on them). Compiling D however, is a lot faster than 
compiling C++, therefore the first method is usually preferrable.


More information about the Digitalmars-d-learn mailing list