Thread overview
module dhelper is in file 'dhelper.d' which cannot be read
Jun 30, 2013
Milvakili
Jul 01, 2013
Adam D. Ruppe
Jul 01, 2013
Milvakili
Jul 01, 2013
Marco Leise
June 30, 2013
I'm new to D and got confused with the dmd.  I assume I have the following codes in some folder x with all relevant extra files. Should use .di files to import from other modules or the d file itself is sufficient to import a module

In c++, gcc -c x/cmain.cpp wil compile without any error.

****cmain.cpp***
#include <iostream>
#include "chelper.h"

int main(){
  std::cout << "Printing from cmain\n" ;
  chelper_foo("cmain");
  return 0;
}

In D, dmd -c x/dmain.d will complainsabout dhelper.d file which is in the x folder.  What should I do to get  rid of this error?  dmd -c x/dmain.d x/dhelper.d compiles but I do not want that.

****dmain.d***
import std.stdio;
import dhelper;

void main(){
  writefln("Hi from d");
  dhelper_foo("dmain");
}
July 01, 2013
On Sun, 30 Jun 2013 19:58:51 -0400, Milvakili <maliy.kayit@gmail.com> wrote:

> I'm new to D and got confused with the dmd.  I assume I have the following codes in some folder x with all relevant extra files. Should use .di files to import from other modules or the d file itself is sufficient to import a module
>
> In c++, gcc -c x/cmain.cpp wil compile without any error.
>
> ****cmain.cpp***
> #include <iostream>
> #include "chelper.h"
>
> int main(){
>    std::cout << "Printing from cmain\n" ;
>    chelper_foo("cmain");
>    return 0;
> }
>
> In D, dmd -c x/dmain.d will complainsabout dhelper.d file which is in the x folder.  What should I do to get  rid of this error?  dmd -c x/dmain.d x/dhelper.d compiles but I do not want that.
>
> ****dmain.d***
> import std.stdio;
> import dhelper;
>
> void main(){
>    writefln("Hi from d");
>    dhelper_foo("dmain");
> }

The compiler can't find the dhelper source.  It looks in your search path, and then at the module path.

For example, if you did:

import x.dhelper;

it would compile main.  But then of course, dhelper better be told that it's x.dhelper and not just dhelper :)

// inside dhelper.d
module x.dhelper;

-Steve
July 01, 2013
It might help to add -Ix to dmd, which adds the x folder to your import search path.

I haven't actually tried it though. I compile my D programs with all the files listed on the command line at once, I find it is simpler and often a little faster too.
July 01, 2013
On Monday, 1 July 2013 at 00:35:07 UTC, Adam D. Ruppe wrote:
> It might help to add -Ix to dmd, which adds the x folder to your import search path.
>
> I haven't actually tried it though. I compile my D programs with all the files listed on the command line at once, I find it is simpler and often a little faster too.

-I option is working for me, but the confusing thing is g++ can handle this by default but dmd require it to be explicitly added.

I have a situation that each code needs to be compiled individually :).

Thankx.

July 01, 2013
Am Mon, 01 Jul 2013 03:43:27 +0200
schrieb "Milvakili" <maliy.kayit@gmail.com>:

> On Monday, 1 July 2013 at 00:35:07 UTC, Adam D. Ruppe wrote:
> > It might help to add -Ix to dmd, which adds the x folder to your import search path.
> >
> > I haven't actually tried it though. I compile my D programs with all the files listed on the command line at once, I find it is simpler and often a little faster too.
> 
> -I option is working for me, but the confusing thing is g++ can handle this by default but dmd require it to be explicitly added.
> 
> I have a situation that each code needs to be compiled individually :).
> 
> Thankx.
> 

In D every directory is a package in the module system.
The root of that is where you invoke the compiler.

So if all your code is in "x" or in "source" or whatever you can either switch into that directory to compile or add -Ix to the compiler command-line.

If "x" is in fact a package in your case when you think about it, use the correct "import x.dhelper;"

P.S.: You never need .di files unless you have to hide the implementation. And when you use them, they are handled exactly the same as their original .d file.

-- 
Marco