Setting import paths - project (dub) and also rdmd or dmd

Christian Köstlin christian.koestlin at gmail.com
Mon Sep 19 21:06:10 UTC 2022


On 19.09.22 16:24, David wrote:
> Hi,
> 
> New to D (and enjoying the learning..) I've probably missed something 
> obvious but I'm slightly confused with the best way to achieve a simple 
> build.
> 
> I like to keep my reusable modules in a directory outside of the project 
> directory so I can use them on another project for example.
> 
> I do :-
> 
> import externalmodulename;
> 
> rdmd app.d and get a fail.
> 
> No problems, I can run rdmd thus :-
> 
> rdmd -I../EXTERNALMODULES app.d
> 
> and it all compiles nicely.
> 
> Same goes for dmd just use dmd -I and it compiles the code clean.
> 
> I'd normally just have a CPPFLAGS=... line in a classic Makefile to do 
> this for me but can't see a native D way of doing it.  I looked at dub 
> and that that :-
> 
> dub add-path ../EXTERNALMODULES
> 
> would do the trick but it doesn't make a difference (the path is added 
> to the relevant json file in ~/.dub), I also tried add-local but no 
> difference.  I was expecting it to add something to dub.sdl but that 
> hasn't changed since I created the project.
> 
> TLDR: How do I automatically specify the -I to the compilers so I don't 
> need to specify it manually each time ?
> 
> 
> Regards,
> 
> 
> D
Another option that goes completely around the -I issue is if you make 
your module into a full dub package and add this with dub add-local. 
Then it becomes available as a regular dub dependency, which can be used 
in dub builds as well as in rdmd builds (see 
https://dub.pm/advanced_usage#single-file). Not sure how to solve the 
dmd thing though, besides what Steven proposed.

Kind regards,
Christian




More information about the Digitalmars-d-learn mailing list