digitalmars.D.learn - Hiding implementations
- Bill Baxter (5/5) Oct 16 2006 Since D has no header files, is it possible to distribute binary-only
- Derek Parnell (33/39) Oct 16 2006 D does have 'header' files. By convention they have the suffix ".di" and
- Bill Baxter (6/52) Oct 16 2006 Excellent. Thanks.
- Sean Kelly (4/57) Oct 16 2006 Note that the auto-generated headers will include the bodies of
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
Oct 16 2006
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? --bbD 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
Oct 16 2006
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? --bbD 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.
Oct 16 2006
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? --bbD 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.
Oct 16 2006