digitalmars.D.learn - About modules
- Damian (8/8) Jul 24 2006 I'm with gdc on linux, And think I dont understand how
- Regan Heath (12/20) Jul 24 2006 If you tell DMD that your import path is the 'root' the one which contai...
- Damian (4/32) Jul 24 2006 Perfect! Thanks!
- Derek (32/42) Jul 24 2006
- Damian (3/8) Jul 24 2006 :)
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..." Thanks and sorry for my strange english!
Jul 24 2006
On Mon, 24 Jul 2006 17:18:27 -0300, Damian <damian.pop gmail.com> 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..." Thanks and sorry for my strange english!If you tell DMD that your import path is the 'root' the one which contains 'main' then in /main/something/moda.d you could write "import main.gui.modb;". Likewise, in /main/gui/modb.d you would write "import main.something.moda;". The import package/module/file is relative to the import path root(s). The file sc.ini in dmd/bin/ tells it where the import path root(s) are, eg: DFLAGS="-I% P%\..\src\phobos;% P%\..\..\src" The -I is for import paths, note that I have added % P%\..\..\src (I'm on windows), this is my import path root for most of my D source code. % P% resolves to the dmd/bin directory. Regan
Jul 24 2006
Perfect! Thanks! Anyone knows how can I set the import path root using gdc? It has no sc.ini file. On Tue, 25 Jul 2006 10:33:28 +1200, Regan Heath wrote:On Mon, 24 Jul 2006 17:18:27 -0300, Damian <damian.pop gmail.com> 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..." Thanks and sorry for my strange english!If you tell DMD that your import path is the 'root' the one which contains 'main' then in /main/something/moda.d you could write "import main.gui.modb;". Likewise, in /main/gui/modb.d you would write "import main.something.moda;". The import package/module/file is relative to the import path root(s). The file sc.ini in dmd/bin/ tells it where the import path root(s) are, eg: DFLAGS="-I% P%\..\src\phobos;% P%\..\..\src" The -I is for import paths, note that I have added % P%\..\..\src (I'm on windows), this is my import path root for most of my D source code. % P% resolves to the dmd/bin directory. Regan
Jul 24 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!"
Jul 24 2006
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.Ok, that's what i'll do.:) Thanks for your help!Thanks and sorry for my strange english!Looks pretty good to me.
Jul 24 2006