Import paths do not work

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 28 23:14:47 PST 2015


On 29/01/2015 8:08 p.m., tcak wrote:
> I have a library that has many folders and D files in them. I do not
> want to list name of all module files one by one while compiling
> projects. So, I thought I could use "-I" flag while compiling. It says:
>
> -Ipath
>      where to look for imports
>
> So, I made a test as follows:
>
>
> ./test.d
> ==================================
> import inc.blah;
>
> void main(){
>      inc.blah.a = 5;
> }
>
>
> ./inc/blah.d
> ==================================
> module inc.blah;
>
> public int a;
>
>
> ./makefile
> ==================================
> all:
>      dmd -I"./inc/" test.d
>
>
> When I do "make", result is as follows:
>
> dmd -I"./inc/" test.d
> test.o: In function `_Dmain':
> test.d:(.text._Dmain+0x10): undefined reference to `_D3inc4blah1ai'
>
>
> Do I understand wrong how that "-I" flag works?

Basically during linking not all symbols used is passed in.
You are doing a single compile + link.
So what -I does is tell the compiler to look for definitions in files on 
the paths specified. But does not compile them into the binary output.

I would suggest instead of using make, use dub[0] build manager instead.
It'll handle grabbing all the files and compiling them correctly.

[0] http://code.dlang.org/package-format


More information about the Digitalmars-d-learn mailing list