digitalmars.D.learn - Setting import paths - project (dub) and also rdmd or dmd
- David (26/26) Sep 19 2022 Hi,
- Steven Schveighoffer (4/6) Sep 19 2022 For dmd, dmd.conf: https://dlang.org/dmd-osx.html#dmd-conf
- =?UTF-8?Q?Christian_K=c3=b6stlin?= (9/51) Sep 19 2022 Another option that goes completely around the -I issue is if you make
- David (18/18) Oct 01 2022 Thank you Steven and Christian.
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
Sep 19 2022
On 9/19/22 10:24 AM, David wrote:TLDR: How do I automatically specify the -I to the compilers so I don't need to specify it manually each time ?For dmd, dmd.conf: https://dlang.org/dmd-osx.html#dmd-conf I believe for all compilers, there's an equivalent config file. -Steve
Sep 19 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, DAnother 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
Sep 19 2022
Thank you Steven and Christian. I had a look at both those methods, creating a local dmd.conf file almost worked but it wasn't a simple modification, I was hoping it would be as simple as just adding the extra path but it seems that I needed to add the whole path from the existing dmd.conf otherwise the build broke due to not being able to find stuff, I added extra stuff but it was a clumsy solution... Local dub packages I'm not not quite ready to do properly on this part of the learning curve and it is something I looked at and I think that I may end up using this. In the end I cheated. I simply added symlinks in my source directory to the *.d files I wanted to import and that solved the problem. It's probably(certainly ?) not the best way to do it but it works and as I become better with D I'm pretty sure I'll change it to something more sensible. Regards, D
Oct 01 2022