About modules

Derek derek at psyc.ward
Mon Jul 24 16:05:29 PDT 2006


On Mon, 24 Jul 2006 17:18:27 -0300, Damian wrote:

> I'm with gdc on linux, And think I dont understand how
> files/packages/modules works.
> I am organizing files in folders like this:
> 
> /main/something/moda.d
> /main/gui/modb.d
> 
> in modb.d: Can I import moda?
> I get "module modb cannot read file..."
 

The module and package names in an import statement are *not* relative to
the file importing them. This is a common misunderstanding so don't worry.
Instead, there are relative to "import paths". An import path is a starting
place to scan for modules. The import paths can be specified in two
places:-
 (1) The command line switch "-I". You can have any number of these and
they specify an import path. E.G. -I/main/something -I/main/gui

 (2) The file "dmd.conf" (for Linux) which can be in ...
     -> current working directory
     -> directory specified by the HOME environment variable
     -> directory dmd resides in
     -> /etc/ 
  contains a line similar to 

    DFLAGS="-I%@P%/../src/phobos"
  You can extend this line with other default import paths, but watch out
when installing new versions of DMD as your changes are overwritten.

I'm not sure that GDC supports the dmd.conf file idea so you may have to
supply all import paths on the command line.

Anyhow, if you source file contains...
  import moda;

then you need an import path for "/main/something" so that the compiler can
find it.

Likewise if the import statement say "import something.moda;" then the
import path should be "/main" and the module statement in moda.d should be
"module something.moda;"

> Thanks and sorry for my strange english!

Looks pretty good to me.

-- 
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"



More information about the Digitalmars-d-learn mailing list