Whether it is possible to produce PURELY statically linked program in D , just like C++

Iain Buclaw ibuclaw at ubuntu.com
Thu Sep 13 03:54:18 PDT 2012


On 13 September 2012 10:25, deeproot <deeprootdeeproot at gmail.com> wrote:
> For C++
>
>    $ cat hello.cpp
>         #include <iostream>
>         using namespace std;
>         int main() {
>          cout << "hello";
>          return 0;
>         }
>
>    $ g++ hello.cpp -o hello
>
>    $ ldd hello
>         linux-gate.so.1 =>  (0xb7703000)
>         libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6
> (0xb7607000)
>         libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7462000)
>         libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7435000)
>         /lib/ld-linux.so.2 (0xb7704000)
>         libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7417000)
>
> Now i am trying to produce static executable in C++
>    $ g++ -static hello.cpp -o hello
>
>    $ ldd hello
>         not a dynamic executable
>
>
> ==================================
> Now For D:
> hello world D program has multiple dependencies
>    $ cat hello.d
>       import std.stdio;
>       void main(){writefln("%s World!", "Hello");}
>
>    $ gdc hello.d
>    $ ldd a.out
>
>         linux-gate.so.1 =>  (0xb771a000)
>         libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb76d7000)
>         librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb76ce000)
>         libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb76af000)
>         libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0
> (0xb7694000)
>         libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb74ef000)
>         /lib/ld-linux.so.2 (0xb771b000)
>
> ===========
> Now, when i compile with -static flag to gdc then i get following
> warnings
>     $ gdc -static hello.d
>
> /usr/lib/gcc/i686-linux-gnu/4.6/libgphobos2.a(path.o): In
> function
> `_D3std4path11expandTildeFAyaZAya18expandFromDatabaseFAyaZAya':
> (.text+0x335): warning: Using 'getpwnam_r' in statically linked
> applications requires at runtime the shared libraries from the
> glibc version used for linking
> /usr/lib/gcc/i686-linux-gnu/4.6/libgphobos2.a(stdio.o): In
> function `_D3std5stdio11openNetworkFAyatZS3std5stdio4File':
> (.text+0x3d35): warning: Using 'gethostbyname' in statically
> linked applications requires at runtime the shared libraries from
> the glibc version used for linking
>
> There is no reason that my just dead simple hello world program
> should be linked with getpwnam_r and gethostbyname
> ========
> in the same way, dmd compiler produced executable also is
> dynamically linked  only.
> Now, my question is that, whether like C/C++ i can actually get a
> helloworld (that no complex dependencies) program FULLY
> statically linked in D.
>

I know what needs to be done from the gdc driver side - this will be
resolved tonight.

Regards
-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d mailing list