Thread overview
Passing directory as compiler argument not finding file
Apr 12, 2018
Jamie
Apr 12, 2018
Nicholas Wilson
Apr 12, 2018
Nicholas Wilson
Apr 12, 2018
Tony
Apr 12, 2018
Jamie
Apr 12, 2018
Nicholas Wilson
Apr 13, 2018
Tony
Apr 13, 2018
Cym13
Apr 13, 2018
Tony
Apr 13, 2018
Cym13
April 12, 2018
With a directory structure as follows:

    run/
    A/
        a.d

Where a.d is:
    ===========
    module A.d;


I'm attempting to compile from the run/ directory. If I run with
    dmd ../A/a.d

it compiles successfully, however if I pass it the directory
    dmd -I=../A a.d

it doesn't compile. Also, if I pass the exact directory
    dmd -I=/../A a.d

it doesn't compile.

Both times I get the error
Error: module `a` is in the file 'a.d' which cannot be read

However it then shows the import path as being
import path[0] = ../A

for the first way and
import path[0] = /../A
for the second way.

Am I using the -I compiler option incorrectly?
April 12, 2018
On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote:
> With a directory structure as follows:
>
>     run/
>     A/
>         a.d
>
> Where a.d is:
>     ===========
>     module A.d;
>
>
> I'm attempting to compile from the run/ directory. If I run with
>     dmd ../A/a.d
>
> it compiles successfully, however if I pass it the directory
>     dmd -I=../A a.d
>
> it doesn't compile. Also, if I pass the exact directory
>     dmd -I=/../A a.d
>
> it doesn't compile.
>
> Both times I get the error
> Error: module `a` is in the file 'a.d' which cannot be read
>
> However it then shows the import path as being
> import path[0] = ../A
>
> for the first way and
> import path[0] = /../A
> for the second way.
>
> Am I using the -I compiler option incorrectly?

is it thinking /../A is an absolute path?
try -I=./../A
April 12, 2018
On Thursday, 12 April 2018 at 06:22:30 UTC, Nicholas Wilson wrote:
> On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote:
>> Am I using the -I compiler option incorrectly?
>
> is it thinking /../A is an absolute path?
> try -I=./../A

Er, scratch that.  I see you already tried it.
April 12, 2018
On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote:

> Am I using the -I compiler option incorrectly?

I believe so. I think it is for finding import files, not the files you are compiling.

---------------------------------------------------------
-I=directory
     Look for imports also in directory

April 12, 2018
On Thursday, 12 April 2018 at 06:30:25 UTC, Tony wrote:
> On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote:
>
>> Am I using the -I compiler option incorrectly?
>
> I believe so. I think it is for finding import files, not the files you are compiling.
>
> ---------------------------------------------------------
> -I=directory
>      Look for imports also in directory

Ahh yes I think you are correct. It sounds silly that I was compiling from a different spot to my file, but it was to demonstrate my situation. Really, it's more like:

A/
 a.d
    module A.a;
    import std.stdio;
    import B.b;
    void main()
    {
        writeln(f(4));
    }
B/
 b.d
    module B.b;
    size_t f(size_t input)
    {
        return input * 2;
    }

And in A/ I'm compiling
    dmd -ofoutput a.d ../B/b.d

and instead I was thinking I could compile with
    dmd -ofoutput a.d -I../B b.d

and would get the same result. The former works, the latter does not. Is there something like this that I can use or do I have to pass all the files with the direct path to them? Thanks

April 12, 2018
On Thursday, 12 April 2018 at 07:48:28 UTC, Jamie wrote:
> On Thursday, 12 April 2018 at 06:30:25 UTC, Tony wrote:
>> On Thursday, 12 April 2018 at 05:39:21 UTC, Jamie wrote:
>>
>>> Am I using the -I compiler option incorrectly?
>>
>> I believe so. I think it is for finding import files, not the files you are compiling.
>>
>> ---------------------------------------------------------
>> -I=directory
>>      Look for imports also in directory
>
> Ahh yes I think you are correct. It sounds silly that I was compiling from a different spot to my file, but it was to demonstrate my situation. Really, it's more like:
>
> A/
>  a.d
>     module A.a;
>     import std.stdio;
>     import B.b;
>     void main()
>     {
>         writeln(f(4));
>     }
> B/
>  b.d
>     module B.b;
>     size_t f(size_t input)
>     {
>         return input * 2;
>     }
>
> And in A/ I'm compiling
>     dmd -ofoutput a.d ../B/b.d
>
> and instead I was thinking I could compile with
>     dmd -ofoutput a.d -I../B b.d
>
> and would get the same result. The former works, the latter does not. Is there something like this that I can use or do I have to pass all the files with the direct path to them? Thanks

rdmd. from the directory above A and B:

$ rdmd -ofoutput A/a.d
April 13, 2018
On Thursday, 12 April 2018 at 07:48:28 UTC, Jamie wrote:
 Really, it's more like:
>
> A/
>  a.d
>     module A.a;
>     import std.stdio;
>     import B.b;
>     void main()
>     {
>         writeln(f(4));
>     }
> B/
>  b.d
>     module B.b;
>     size_t f(size_t input)
>     {
>         return input * 2;
>     }
>
> And in A/ I'm compiling
>     dmd -ofoutput a.d ../B/b.d
>
> and instead I was thinking I could compile with
>     dmd -ofoutput a.d -I../B b.d
>
> and would get the same result. The former works, the latter does not. Is there something like this that I can use or do I have to pass all the files with the direct path to them? Thanks

I think that the typical model (at least in other languages) is to only compile one D source file at a time. Compile the b.d file with the -c option to create an object file. Then put the object file in a library file (either static (easier) or dynamic). Then you can use the -L compiler option to specify the directory of the library and the -l  compiler option to specify the library (library name is shortened - libb.a referenced as -lb).

April 13, 2018
On Friday, 13 April 2018 at 01:27:06 UTC, Tony wrote:
> I think that the typical model (at least in other languages) is to only compile one D source file at a time. Compile the b.d file with the -c option to create an object file. Then put the object file in a library file (either static (easier) or dynamic). Then you can use the -L compiler option to specify the directory of the library and the -l  compiler option to specify the library (library name is shortened - libb.a referenced as -lb).

Regardless of whether that would work or not this is the opposite of what's recommended in D. D compilers expect you to compile everything at once, or at least by module. That's where it works best when it comes to optimizations etc.
April 13, 2018
On Friday, 13 April 2018 at 12:46:32 UTC, Cym13 wrote:
> On Friday, 13 April 2018 at 01:27:06 UTC, Tony wrote:
>> I think that the typical model (at least in other languages) is to only compile one D source file at a time. Compile the b.d file with the -c option to create an object file. Then put the object file in a library file (either static (easier) or dynamic). Then you can use the -L compiler option to specify the directory of the library and the -l  compiler option to specify the library (library name is shortened - libb.a referenced as -lb).
>
> Regardless of whether that would work or not this is the opposite of what's recommended in D. D compilers expect you to compile everything at once, or at least by module. That's where it works best when it comes to optimizations etc.

What does "or at least by module" mean? Is it possible to have a module that is made up of more than one source file?

What information does a D compiler get when you stick a.d and b.d on the command line that it doesn't get if you compile a.d and import b.d ?
April 13, 2018
On Friday, 13 April 2018 at 13:39:23 UTC, Tony wrote:
> On Friday, 13 April 2018 at 12:46:32 UTC, Cym13 wrote:
>> On Friday, 13 April 2018 at 01:27:06 UTC, Tony wrote:
>>> I think that the typical model (at least in other languages) is to only compile one D source file at a time. Compile the b.d file with the -c option to create an object file. Then put the object file in a library file (either static (easier) or dynamic). Then you can use the -L compiler option to specify the directory of the library and the -l  compiler option to specify the library (library name is shortened - libb.a referenced as -lb).
>>
>> Regardless of whether that would work or not this is the opposite of what's recommended in D. D compilers expect you to compile everything at once, or at least by module. That's where it works best when it comes to optimizations etc.
>
> What does "or at least by module" mean? Is it possible to have a module that is made up of more than one source file?

Sorry, I really meant "package" here, not module.

> What information does a D compiler get when you stick a.d and b.d on the command line that it doesn't get if you compile a.d and import b.d ?

Hmm. I can't quite remember honnestly. What I do remember is Andrei saying times and times again that D supports compilation by package and not incremental compilation (which is difficult because of CTFE and templates), but on second thought maybe you won't run into issues if compiling each module separately as long as you compile them all. However I'm pretty sure you'll get worse compilation times as the compiler can't make use of symbol cache etc. That may be the main reason why people generally avoid compiling separately each module and just put every file on the command line. AFAIK dmd is designed to be used that way.