www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std libraries vs. personal libraries

reply jicman <jicman_member pathlink.com> writes:
I have these two programs:
// test.d
private import std.string;
private import std.stdio;
private import std.date;
private import std.file;
private import std.recls;
private import jic.lib.misc;

int main(char[][] args) { return(0); }

and

// test0.d
private import std.string;
private import std.stdio;
private import std.date;
private import std.file;
private import std.recls;

int main(char[][] args) { return(0); }


When I compile test.d, I get:

15:20:05.13>build -I.. test.d
c:\dmd\bin\..\..\dm\bin\link.exe
C:\cygwin\home\us319318\source\d\jic\lib\misc_bn+C:\cygwin\home\us319318\source\d\jic\lib\misc+RemFiles_bn+test,test.exe,,user32+kernel32,test.def/noi;

and the size of the test.exe file is 162,844 bytes.  However, when I compile
test0.d, I get:

15:24:03.45>build -I.. test0.d
c:\dmd\bin\..\..\dm\bin\link.exe test0,test0.exe,,user32+kernel32,test0.def/noi;

and the size of the test0.exe file is 86,556 bytes.

Now, I see that my personal library is getting added also, but I am not adding
anything to the program.  Why is the personal library getting added by the
compiler when I am not calling any functions from it?

Could it be build?
Mar 16 2006
next sibling parent reply jicman <jicman_member pathlink.com> writes:
Ok, so I tried dmd and it builds both files ok and with the same file size
(below):

16:05:42.78>dmd -I.. test.d
c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi;

16:06:02.14>dmd -I.. test0.d
c:\dmd\bin\..\..\dm\bin\link.exe test0,,,user32+kernel32/noi;

03/16/2006  04:28 PM            86,556 test.exe
03/16/2006  04:28 PM            86,556 test0.exe

So, apparently, is build.

Derek? :-)


jicman says...
I have these two programs:
// test.d
private import std.string;
private import std.stdio;
private import std.date;
private import std.file;
private import std.recls;
private import jic.lib.misc;

int main(char[][] args) { return(0); }

and

// test0.d
private import std.string;
private import std.stdio;
private import std.date;
private import std.file;
private import std.recls;

int main(char[][] args) { return(0); }


When I compile test.d, I get:

15:20:05.13>build -I.. test.d
c:\dmd\bin\..\..\dm\bin\link.exe
C:\cygwin\home\us319318\source\d\jic\lib\misc_bn+C:\cygwin\home\us319318\source\d\jic\lib\misc+RemFiles_bn+test,test.exe,,user32+kernel32,test.def/noi;

and the size of the test.exe file is 162,844 bytes.  However, when I compile
test0.d, I get:

15:24:03.45>build -I.. test0.d
c:\dmd\bin\..\..\dm\bin\link.exe test0,test0.exe,,user32+kernel32,test0.def/noi;

and the size of the test0.exe file is 86,556 bytes.

Now, I see that my personal library is getting added also, but I am not adding
anything to the program.  Why is the personal library getting added by the
compiler when I am not calling any functions from it?

Could it be build?
Mar 16 2006
parent John Reimer <terminal.node gmail.com> writes:
Yes, I believe jicman wrote:
 Ok, so I tried dmd and it builds both files ok and with the same file size
 (below):
 
 16:05:42.78>dmd -I.. test.d
 c:\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi;
 
 16:06:02.14>dmd -I.. test0.d
 c:\dmd\bin\..\..\dm\bin\link.exe test0,,,user32+kernel32/noi;
 
 03/16/2006  04:28 PM            86,556 test.exe
 03/16/2006  04:28 PM            86,556 test0.exe
 
 So, apparently, is build.
 
 Derek? :-)
 
 
I believe that by default 'build' compiles and links in files that may be "import-only", so pretty much anything that might be referenced in the imports will be included in the final executable. That means you may get files in there that merely declare a bunch of symbols: like the ones that use extern(C) or extern(Windows) for external libraries -- you don't need the object form of those modules since they just contain symbol definitions for the external libraries. Compiling all those symbols and putting the object into your project is going to bloat up the executable, I imagine. If you know which files are really just import header modules, maybe try using builds exclude function on the command line: -X(module or package). Did you try -Xphobos? That might help. -JJR
Mar 16 2006
prev sibling parent reply "Derek Parnell" <derek psych.ward> writes:
On Fri, 17 Mar 2006 08:06:07 +1100, jicman <jicman_member pathlink.com>  
wrote:

 I have these two programs:
 // test.d
 private import std.string;
 private import std.stdio;
 private import std.date;
 private import std.file;
 private import std.recls;
 private import jic.lib.misc;

 int main(char[][] args) { return(0); }

 and

 // test0.d
 private import std.string;
 private import std.stdio;
 private import std.date;
 private import std.file;
 private import std.recls;

 int main(char[][] args) { return(0); }


 When I compile test.d, I get:

 15:20:05.13>build -I.. test.d
 c:\dmd\bin\..\..\dm\bin\link.exe
 C:\cygwin\home\us319318\source\d\jic\lib\misc_bn+C:\cygwin\home\us319318\source\d\jic\lib\misc+RemFiles_bn+test,test.exe,,user32+kernel32,test.def/noi;

 and the size of the test.exe file is 162,844 bytes.  However, when I  
 compile
 test0.d, I get:

 15:24:03.45>build -I.. test0.d
 c:\dmd\bin\..\..\dm\bin\link.exe  
 test0,test0.exe,,user32+kernel32,test0.def/noi;

 and the size of the test0.exe file is 86,556 bytes.

 Now, I see that my personal library is getting added also, but I am not  
 adding
 anything to the program.  Why is the personal library getting added by  
 the
 compiler when I am not calling any functions from it?

 Could it be build?
Yes. If the module 'jic.lib.misc' contains nothing that should be linked in, you can add a pragma to it to stop Build from linking it. version(build) pragma(nolink); This can be added anywhere in the 'jic.lib.misc.d' source file. Typically, you would do this if the source file only contained header info and no function bodies and/or public variables. -- Derek Parnell Melbourne, Australia
Mar 18 2006
parent John Reimer <John_member pathlink.com> writes:
In article <op.s6l0j8f26b8z09 ginger.vic.bigpond.net.au>, Derek Parnell says...
Yes. If the module 'jic.lib.misc' contains nothing that should be linked  
in, you can add a pragma to it to stop Build from linking it.

   version(build) pragma(nolink);

This can be added anywhere in the 'jic.lib.misc.d' source file.

Typically, you would do this if the source file only contained header info  
and no function bodies and/or public variables.

-- 
Derek Parnell
Melbourne, Australia
A point I was wondering about: version(build) pragma(nolink) is certainly useful, but in most situations these types of modules don't need to be compiled at all since they are headers. So wouldn't it be better (or at least more efficient) to have a pragma that specified "nocompile" or something similar to avoid an unnecessary step? Currently, using the -full and -X<module> flags together on the build command line seems to achieve this goal. -full "causes all source files, except ignored modules, to be compiled." But there is no equivalent in a pragma version. This would seem more suitable in a header-type module situation as described above. -JJR
Mar 18 2006