How does the compiler look for the files of imports?
Kirk McDonald
kirklin.mcdonald at gmail.com
Tue Sep 18 15:49:22 PDT 2007
Jakob wrote:
> I have the following files:
>
> foo/bar.d
> module foo.bar;
> import lol.rofl;
>
> lol/rofl.d
> module lol.rofl;
>
>
> If i change to the directory where "foo" and "lol" are in, and do
> gdc foo/bar.d lol/rofl.d
> it finds all the files.
>
> If i change to the directory "foo/" and do
> gdc bar.d ../lol/rofl
> it doesn't compile:
> bar.d:3: module rofl cannot read file 'lol/rofl.d'
>
>
> IMHO, the compiler should notice that the module name is 'foo.bar' (and
> not only 'bar') and so the directory to search for imports is the parent
> directory. Or what do you think about that?
I think it requires too much magic.
/
+-foo/
| +-lol/
| | +-rofl.d - module lol.rofl (1)
| +-bar.d - module foo.bar
+-lol/
+-rofl.d - module lol.rofl (2)
If the current directory is the root of the above, then:
$ gdc -c foo/bar.d
That will find the lol.rofl marked (2). But if the current direcrory is
foo/:
$ gdc -c bar.d
This will (currently) find the lol.rofl marked (1).
To answer the question in the subject line, the compiler looks in the
current directory and then any directories provided by the -I option. To
get your second example working, you just need to add "-I .." to the
command-line:
$ gdc bar.d ../lol/rofl.d -I ..
There are too many subtleties involved for the compiler to be able to
guess where modules should be.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list