Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 17, 2006 Hiding implementations | ||||
---|---|---|---|---|
| ||||
Since D has no header files, is it possible to distribute binary-only libraries? With C++ you can ship just header files and compiled libs, then the users can see the interface but not the implementation. How can you do that with D? --bb |
October 17, 2006 Re: Hiding implementations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | On Tue, 17 Oct 2006 11:48:23 +0900, Bill Baxter wrote: > Since D has no header files, is it possible to distribute binary-only libraries? With C++ you can ship just header files and compiled libs, then the users can see the interface but not the implementation. How can you do that with D? > > --bb D does have 'header' files. By convention they have the suffix ".di" and only contain the interface stuff. For example: Implementation file -- mymod.d // ------ start of file ---------- private import std.stdio; void myfunc(int x) { std.stdio.writefln("The ANSWER is %s", x); } // --------- end of file ---------- Interface file -- mymod.di // ------ start of file ---------- private import std.stdio; void myfunc(int x); // --------- end of file ---------- You compile the implementation file and supply either the object file or a library containing the object file. You then use it as ... //--- example import mymod; void main() { mymod.myfunc(42); } // --------- end of file dmd example.d mymod.di thelibrary.lib You can also generate the header file by doing ... dmd myfunc.d -H This will create the myfunc.di file for you. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 17/10/2006 2:05:40 PM |
October 17, 2006 Re: Hiding implementations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Excellent. Thanks.
Sometimes it's nice to have header files around just as a quick reference to what's in a big API. Nice that they can be generated automatically.
--bb
Derek Parnell wrote:
> On Tue, 17 Oct 2006 11:48:23 +0900, Bill Baxter wrote:
>
>> Since D has no header files, is it possible to distribute binary-only libraries? With C++ you can ship just header files and compiled libs, then the users can see the interface but not the implementation. How can you do that with D?
>>
>> --bb
>
> D does have 'header' files. By convention they have the suffix ".di" and
> only contain the interface stuff.
>
> For example:
> Implementation file -- mymod.d
> // ------ start of file ----------
> private import std.stdio;
> void myfunc(int x)
> {
> std.stdio.writefln("The ANSWER is %s", x);
> }
> // --------- end of file ----------
>
> Interface file -- mymod.di
> // ------ start of file ----------
> private import std.stdio;
> void myfunc(int x);
> // --------- end of file ----------
>
>
> You compile the implementation file and supply either the object file or a
> library containing the object file. You then use it as ...
>
> //--- example import mymod;
> void main() { mymod.myfunc(42); }
> // --------- end of file
>
>
> dmd example.d mymod.di thelibrary.lib
>
> You can also generate the header file by doing ...
>
> dmd myfunc.d -H
>
> This will create the myfunc.di file for you.
>
|
October 17, 2006 Re: Hiding implementations | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Note that the auto-generated headers will include the bodies of functions eligible for inlining. So depending on your needs, you may want to hand-edit the headers after generation.
Bill Baxter wrote:
> Excellent. Thanks.
> Sometimes it's nice to have header files around just as a quick reference to what's in a big API. Nice that they can be generated automatically.
>
> --bb
>
> Derek Parnell wrote:
>> On Tue, 17 Oct 2006 11:48:23 +0900, Bill Baxter wrote:
>>
>>> Since D has no header files, is it possible to distribute binary-only libraries? With C++ you can ship just header files and compiled libs, then the users can see the interface but not the implementation. How can you do that with D?
>>>
>>> --bb
>>
>> D does have 'header' files. By convention they have the suffix ".di" and
>> only contain the interface stuff.
>>
>> For example:
>> Implementation file -- mymod.d
>> // ------ start of file ----------
>> private import std.stdio;
>> void myfunc(int x)
>> {
>> std.stdio.writefln("The ANSWER is %s", x);
>> }
>> // --------- end of file ----------
>>
>> Interface file -- mymod.di
>> // ------ start of file ----------
>> private import std.stdio;
>> void myfunc(int x);
>> // --------- end of file ----------
>>
>>
>> You compile the implementation file and supply either the object file or a
>> library containing the object file. You then use it as ...
>>
>> //--- example import mymod;
>> void main() { mymod.myfunc(42); }
>> // --------- end of file
>>
>>
>> dmd example.d mymod.di thelibrary.lib
>> You can also generate the header file by doing ...
>>
>> dmd myfunc.d -H
>>
>> This will create the myfunc.di file for you.
>>
|
Copyright © 1999-2021 by the D Language Foundation