Thread overview
GDC Compilation wtih Directory Present
Jun 16, 2023
Murloc
Jun 16, 2023
Murloc
Jun 16, 2023
Mike Parker
June 16, 2023

My project structure is the following:

Test
|
+-- pack
|   |
|   +-- file1.d
|   |
|   +-- file2.d
|
+-- program.d

And here is the code inside these files:

// file2.d
package int value = -120;
// file1.d
void printlnValueInFile2() {
    import std.stdio: writeln;
    import pack.file2: value;

    writeln(value);
}
// 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)
June 16, 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).
June 16, 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:

>

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.

module pack.file1;

// file1.d
void printlnValueInFile2() {
     import std.stdio: writeln;
     import pack.file2: value;

     writeln(value);
}
module pack.file2;

package(pack) int value = -120;

Its also a good habit to write the package attribute with explicit package(s).

Thanks! That works well. I thought that module pack.file1 is implicitly there by default :')

June 16, 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.