September 20, 2013
On Friday, 20 September 2013 at 16:50:50 UTC, Adam D. Ruppe wrote:
> On Friday, 20 September 2013 at 16:44:30 UTC, Temtaime wrote:
>> Why? I have a large project.
>> If i replace main with "void main() {}" the size is still 26 MB in debug.
>
> Could be due to things like static module constructors or typeinfos. There *are* problems with things getting intertwined and not being considered dead by the linker, but it does try.
>
> The proof of it is hello world being 150 KB instead of the 6 MB or so it would be if it carried all of the dead code from phobos too.

You are confusing linking static library and eliminating unused code from executable binary itself.
September 20, 2013
I haven't any static constructors.
DMD eliminates nothing. It even doesn't eliminates unreferenced data as i wrote on some bugreport.
September 20, 2013
On Friday, 20 September 2013 at 17:00:22 UTC, Temtaime wrote:
> I haven't any static constructors.
> DMD eliminates nothing. It even doesn't eliminates unreferenced data as i wrote on some bugreport.

It is not possible to eliminate it within current language spec because of shared libraries.
September 20, 2013
On Friday, 20 September 2013 at 16:54:45 UTC, Dicebot wrote:oo.
> You are confusing linking static library and eliminating unused code from executable binary itself.

Well, damn, I just tested with a quick static array and you're right. Damn son.
September 20, 2013
Linker knows what it links i think. :)
So it can eliminate everything that unreferenced in main, isn't i right?
September 20, 2013
On Friday, 20-Sep-13 10:45 AM, Adam D. Ruppe wrote:
> On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:
>> Why such a huge difference???
>
> The D program carries its additional D runtime library code with it,
> whereas the C program only depends on libraries provided by the
> operating system, and thus it doesn't have to include it in the exe.

Now that I know _why_ , is there a way to shave tons off those executables? Any optimization possible?
September 20, 2013
On Friday, 20-Sep-13 10:50 AM, Temtaime wrote:
> C/C++ applications also carries on its runtime(mingwm10, msvc's
> redist, for example).
> If compiled with static runtime, msvc's hello world application uses
> about 40 KB.

+1
September 20, 2013
On 2013-09-20 10:03, Duke Normandin wrote:
> I'm re-visiting the D language. I've compared the file sizes of 2 executables - 1 is compiled C code using gcc; the other is D code using dmd.
>
> helloWorld.d => helloWorld.exe = 146,972 bytes
> ex1hello.c => ex1-hello.exe = 5,661 bytes
>
> Why such a huge difference???
>
> Duke

maybe somehow related:

i have a short program using GtkD. the exe is
~3MB if compiled using dmd and linked to pre-built GtkD.lib (16MB)
~2MB if compiled via bud/build following up on all imports directly, no linking to pre-built lib

all compiler flags the same (-debug for exe, prebuilt lib is not debug but -O -inline -release). on windows.


/det
September 20, 2013
On Friday, 20-Sep-13 10:49 AM, Dicebot wrote:
> On Friday, 20 September 2013 at 16:20:34 UTC, Duke Normandin wrote:
>> I'm re-visiting the D language. I've compared the file sizes of 2
>> executables - 1 is compiled C code using gcc; the other is D code
>> using dmd.
>>
>> helloWorld.d => helloWorld.exe = 146,972 bytes
>> ex1hello.c => ex1-hello.exe = 5,661 bytes
>>
>> Why such a huge difference???
>>
>> Duke
>
> You are doing it wrong.
> ```
> $ gcc hello.c; ls -lah a.out
> -rwxr-xr-x 1 dicebot users 4.9K Sep 20 18:47 a.out
> ```
> vs
> ```
> $ gcc -static hello.c; ls -lah a.out
> -rwxr-xr-x 1 dicebot users 717K Sep 20 18:48 a.out
> ```
>
> (C standard library is dynamically linked by default)
>
> So actual relative difference is about 2x - quite big but not as
> huge. It mostly comes from additional D runtime stuff.

I get the same executable size whether or not I use `-static' with cygwin/win7 ...

Still tons smaller than the D executable though. Not good!! me young mucker!!!!  :D
September 20, 2013
On Friday, 20-Sep-13 11:28 AM, captaindet wrote:
> On 2013-09-20 10:03, Duke Normandin wrote:
>> I'm re-visiting the D language. I've compared the file sizes of 2
>> executables - 1 is compiled C code using gcc; the other is D code
>> using dmd.
>>
>> helloWorld.d => helloWorld.exe = 146,972 bytes
>> ex1hello.c => ex1-hello.exe = 5,661 bytes
>>
>> Why such a huge difference???
>>
>> Duke
>
> maybe somehow related:
>
> i have a short program using GtkD. the exe is
> ~3MB if compiled using dmd and linked to pre-built GtkD.lib (16MB)
> ~2MB if compiled via bud/build following up on all imports directly,
> no linking to pre-built lib
>
> all compiler flags the same (-debug for exe, prebuilt lib is not
> debug but -O -inline -release). on windows.


interesting ....