Thread overview
Designing an API with D.
Oct 01, 2013
Agustin
Oct 01, 2013
evilrat
Oct 02, 2013
Jesse Phillips
October 01, 2013
Hello, i'm trying to make a library and i would like to use that
library on a separated application using only interfaces. I know
how to do it using C++, but i don't known using D. Can anyone
help me?

Project #1
include/*.d -> These are interfaces.
src/*.d     -> Implementation code using those interface.

Project #2
src/*.d     -> Its code using only Project #1's include folder
without implementation code.

Thanks!
October 01, 2013
On Tuesday, 1 October 2013 at 00:37:48 UTC, Agustin wrote:
> Hello, i'm trying to make a library and i would like to use that
> library on a separated application using only interfaces. I know
> how to do it using C++, but i don't known using D. Can anyone
> help me?
>
> Project #1
> include/*.d -> These are interfaces.
> src/*.d     -> Implementation code using those interface.
>
> Project #2
> src/*.d     -> Its code using only Project #1's include folder
> without implementation code.
>
> Thanks!

first, you are in D now, forget C++ way of things please.

AFAIK people rarely use interface files this days, one reason is templates which needs instantiated in ur code but it won't be able to put them in interface files.
(though i may be wrong on it)

still if you need it, check dmd flags, there is option to generate interface files, after this compile ur client code with -I flag like this "dmd -Ipath_to_your_generated_interfaces main.d"

and at last, the simplest way is just to put whole lib sources to client apps, either full source added build, or build static lib first and -I flag in clients.


all i said above is works for open source projects, there may be a few problems exists with interface files at this moment, maybe someone related to compiler development can give you the details.

p.s. i think the most used name for D C++ include folder analog is import(s)
October 02, 2013
On Tuesday, 1 October 2013 at 03:01:32 UTC, evilrat wrote:
> AFAIK people rarely use interface files this days, one reason is templates which needs instantiated in ur code but it won't be able to put them in interface files.
> (though i may be wrong on it)

The interface file needs the entire template implementation, i.e. not the interface.

The -H flag generates the "header files" .di If you are wanting this to hide implementation you'll have better luck writing them by hand. No compiler is checking if .di and .d files match.

D doesn't distinguish between .di or .d so you can use the -I flag on directories listing either.