A question about modules

Myron Alexander someone at somewhere.com
Tue Jun 12 12:55:53 PDT 2007


orgoton wrote:
> I suppose what you mean is to hide the source of you library, and/or not to have the source available at compile time. The solution is simple, pre-compile it.
> In short, compile your library into a .lib file and ask DMD to generate a interface file (.di). Then, on your modules import the .di file and add:
> 
> pragma(lib, "libfile.lib"); //libfile.lib must be inside the dirs searched by DMD
> 
> or add the -Ilibfile.lib to your DMD command. The downside is that you either compile the lib in release/debug mode and that's it. If you want to change the build mode, you'll have to recompile the library. But that's not a real problem.

Orgoton,

I am aware of the .di files (although I did not see that dmd can 
generate them for you so thanks for the info) but what I want to do is 
eliminate the need for a separate .lib and .di files. The way Java works 
  is that you do not have to include a textual header with the .class 
files, the .class files act as the header and obj in one file.

I believe that it is possible to do it for D, but it means some work on 
the front-end and back-end so the linker will have to have an additional 
output mode for D specific modules. You would not be able link a D 
module with a C library directly, the linker would have to extract the 
executable object from the binary module and then link it all together 
into an exe.

Since I have not written a compiler in nearly 2 decades, I will not say 
I know it is possible; I hope someone in the know could inform me on the 
viability of this suggestion.

If there are no technical reasons preventing the implementation of such 
a mechanism, and it is just a matter of Walter not having the time, then 
so be it; but I would like to know, just in case something could be 
worked out.

Best Regards,

Myron.



More information about the Digitalmars-d mailing list