D - more or less power than C++?

Hasan Aljudy hasan.aljudy at gmail.com
Sat Mar 4 20:35:43 PST 2006


Johan Granberg wrote:
> Derek Parnell wrote:
> 
>>> 2. as far as I know no way of inporting somthing in a parent 
>>> directory (as C++ #include "../myheader.hpp")
>>
>>
>> You can, only its not coded in the source file. Instead you do this 
>> via the compiler's "-I" switch.
>>
> 
> Yes it can bee worked around but it's frustrating to have to add a lot 
> of -I by hand to the compiler. It realy complicates keeping a simple 
> makefile.
> 
> An example.
> 
> foo/bar/ff.d
> foo/gg.d
> rr.d
> 
> gg.d imports ff.d with the command import bar.ff;
> rr.d imports gg.d using import foo.d; but now you cant just compile rr.d 
> because the compiler does not find ff.d.
> 
> I realise that my orgina formulation was not so clear. actualy it is not 
> specificaly import from parent dir I want but import relative to the 
> source files dir instead of the dir where the compiler is invoked.
> 
> consider the diference of thees c++ includes
> 
> #include "foo.h" // includes relative to the sourcefiles dir and if that 
> fails in the current path
> 
> #include <foo.h> //includes from path
> 
> and D's import
> 
> import foo; // imports from the search path with the compiler flag -I. 
> added
> 
> wath I want is somthing like the first c++ statement ie an include 
> relative to the sourcefiles location.


The *correct* way of doing it is naming your modules according to the 
directory structure.


----- foo/bar/ff.d ----
module foo.bar.ff;
//rest of file

----- foo/gg.d --------
module foo.gg;
//test of file

----- rr.d ------------
module rr;
//rest of file

now if you want to import rr.d from foo.bar.ff

-----foo/bar/ff.d----
module foo.bar.ff;
import rr;
//rest of file

I think this should work!
When you compile, you have to make sure that the working directory is 
where rr.d resides.






More information about the Digitalmars-d mailing list