digitalmars.D.learn - GDC Compilation wtih Directory Present
- Murloc (44/44) Jun 15 2023 My project structure is the following:
- Richard (Rikki) Andrew Cattermole (18/20) Jun 15 2023 Yes.
- Murloc (4/26) Jun 15 2023 Thanks! That works well. I thought that `module pack.file1` is
- Mike Parker (4/6) Jun 15 2023 The compiler will use the file name as a default module name if
My project structure is the following:
```
Test
|
+-- pack
| |
| +-- file1.d
| |
| +-- file2.d
|
+-- program.d
```
And here is the code inside these files:
```d
// file2.d
package int value = -120;
```
```d
// file1.d
void printlnValueInFile2() {
import std.stdio: writeln;
import pack.file2: value;
writeln(value);
}
```
```d
// program.d
void main() {
import pack.file1;
printlnValueInFile2(); // -120 expected
}
```
From the directory Test when I'm trying to compile the project
with command
`gdc -o program program.d pack/file1.d pack/file2.d`, it produces
3 errors with the following messages:
- module `file1` from file `pack/file1.d` must be imported with
'`import file1;`' (instead of '`import pack.file1`')
- module `file2` from file `pack/file2.d` must be imported with
'`import file2;`' (instead of '`import pack.file2`')
Don't you need to provide a full path to these files relatively
to the directory where the compilation process takes place (Test)?
- module `file2` member '`value`' is not visible from module
'`file1`' (however, both files are in the same directory)
Jun 15 2023
On 16/06/2023 6:26 PM, Murloc wrote:Don't you need to provide a full path to these files relatively to the directory where the compilation process takes place (Test)?Yes. But I suspect you have not written the module statement, which is required. ```d module pack.file1; // file1.d void printlnValueInFile2() { import std.stdio: writeln; import pack.file2: value; writeln(value); } ``` ```d module pack.file2; package(pack) int value = -120; ``` Its also a good habit to write the package attribute with explicit package(s).
Jun 15 2023
On Friday, 16 June 2023 at 06:32:21 UTC, Richard (Rikki) Andrew Cattermole wrote:On 16/06/2023 6:26 PM, Murloc wrote:Thanks! That works well. I thought that `module pack.file1` is implicitly there by default :')Don't you need to provide a full path to these files relatively to the directory where the compilation process takes place (Test)?Yes. But I suspect you have not written the module statement, which is required. ```d module pack.file1; // file1.d void printlnValueInFile2() { import std.stdio: writeln; import pack.file2: value; writeln(value); } ``` ```d module pack.file2; package(pack) int value = -120; ``` Its also a good habit to write the package attribute with explicit package(s).
Jun 15 2023
On Friday, 16 June 2023 at 06:38:17 UTC, Murloc wrote:Thanks! That works well. I thought that `module pack.file1` is implicitly there by default :')The compiler will use the file name as a default module name if you don't provide one, but that's *just* the module name. It doesn't take into account any directories for package names.
Jun 15 2023








Mike Parker <aldacron gmail.com>