digitalmars.D.learn - Odd compiler complaints with import declarations
- Orfeo (33/33) Sep 13 2013 I have this directory hierarchy (from TDPL pag 339):
- Andrej Mitrovic (3/7) Sep 13 2013 Add the module declaration "module acme.gadget;" at the top of
- Orfeo (17/19) Sep 13 2013 Thanks Andrej...
- Adam D. Ruppe (8/10) Sep 13 2013 That statement isn't really true. The module name is what thef
- Orfeo (11/21) Sep 13 2013 OK, but I could not use the module declaration, in this case the
- Adam D. Ruppe (7/9) Sep 13 2013 Yeah, it will have the file name, but not the directory name.
- Orfeo (3/3) Sep 18 2013 See also
I have this directory hierarchy (from TDPL pag 339): . ├── acme │ ├── gadget.d │ └── goodies │ └── io │ ├── io.d │ └── string.d └── main.d // in main.d : import std.stdio; : : import acme.gadget; : void main(string[] args) { : wun(); : } // in gadget.d : import std.stdio; : import acme.goodies.io.string; : public void wun() { } When I try to compile with these files : $ dmd main.d acme/gadget.d acme/goodies/io/*.d -ofa the compiler complains stating... : main.d(3): Error: module gadget from file acme/gadget.d must be imported as module 'gadget' : acme/gadget.d(3): Error: module string from file acme/goodies/io/string.d must be imported as module 'string' But Andrei in his great TDPL writes (pag. 339): "To import one module from another, specify the name of the module in an import declaration. The name must include the relative path computed from the directory" Where am I wrong?
Sep 13 2013
On Friday, 13 September 2013 at 19:54:30 UTC, Orfeo wrote:// in gadget.d : import std.stdio; : import acme.goodies.io.string; : public void wun() { }Add the module declaration "module acme.gadget;" at the top of this file and it should work.
Sep 13 2013
On Friday, 13 September 2013 at 19:57:06 UTC, Andrej Mitrovic wrote:Add the module declaration "module acme.gadget;" at the top of this file and it should work.Thanks Andrej... So, it works also if I add :// main.d :import path.to.nonexistent.location.app; and // gadget.d : module path.to.nonexistent.location.app; but, from TDPL pg 340 "To resolve import path.to.file, for example, the current directory is searched first for a subdirectory path/to. If the directory exists, the file file.di is queried, and if that is not found, the file file.d is queried. If the file has been found, the search ends." Well, if what is written above is true, then why the compiler complains?
Sep 13 2013
On Friday, 13 September 2013 at 19:54:30 UTC, Orfeo wrote:"The name must include the relative path computed from the directory"That statement isn't really true. The module name is what thef ile has in the contents: module foo.test; near the top of the file gives it the name of foo.test. The filename and directory path do *not* have to match and only matter at all for finding the file. The module declaration is all that matters.
Sep 13 2013
On Friday, 13 September 2013 at 20:02:24 UTC, Adam D. Ruppe wrote:On Friday, 13 September 2013 at 19:54:30 UTC, Orfeo wrote:OK, but I could not use the module declaration, in this case the module has the same file name...or not? from http://ddili.org/ders/d.en/modules.html "By default, the name of a module is the same as its filename without the .d extension. When explicitly specified, the name of the module is defined by the module keyword, which must appear as the first non-comment line in the source file. .... The module line is optional. When not specified, it is the same as the file name without the .d extension.""The name must include the relative path computed from the directory"That statement isn't really true. The module name is what thef ile has in the contents: module foo.test; near the top of the file gives it the name of foo.test. The filename and directory path do *not* have to match and only matter at all for finding the file. The module declaration is all that matters.
Sep 13 2013
On Friday, 13 September 2013 at 20:21:31 UTC, Orfeo wrote:OK, but I could not use the module declaration, in this case the module has the same file name...or not?Yeah, it will have the file name, but not the directory name. That's why it called it "module gadget" instead of "module acme.gadget" and that created the error. The rule I use is if you ever import a module, always put the module declaration in the file. Otherwise you'll have problems if the name changes or it moves into a new folder.
Sep 13 2013
See also http://forum.dlang.org/thread/dupcnblrqhesdvwyeuaa forum.dlang.orgOn Friday, 13
Sep 18 2013
Sorry this is correct http://forum.dlang.org/thread/dupcnblrqhesdvwyeuaa forum.dlang.org
Sep 18 2013
See also http://d.puremagic.com/issues/show_bug.cgi?id=11451
Nov 12 2013