www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Static executable (ldc, linux)

reply Anonymouse <zorael gmail.com> writes:
I'm having problems compiling my thing into an executable that 
doesn't require ldc's phobos/druntime .so's. I want to distribute 
it in a form where it's okay if 
`/usr/lib/libphobos2-ldc-shared.so.100` and friends don't exist.

`--static` seems to do the trick in that the compiled file is no 
longer a dynamic executable, but then it doesn't work and just 
segfaults upon trying to use OpenSSL (via `arsd.http2`). The only 
other flag I specifically pass to ldc is `-linkonce-templates`.

```
Linking...
/usr/bin/ld: 
../../.dub/packages/arsd-official-10.9.2/arsd-official/.dub/build/with_openssl-debug-linux.posix-x86_64-ldc_v1.30.0-328F22C7CA122C28C3639482CB724003/libarsd-official_h
tp.a(arsd.http2.o): in function `_D4arsd5http211loadOpenSslFZv':
/home/wob/src/kameloso/../../.dub/packages/arsd-official-10.9.2/arsd-of
icial/http2.d:3679: warning: Using 'dlopen' in statically linked applications
requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(path.o): in function 
`_D3std4path11expandTildeFNbNfAyaZ18expandFromDatabaseFNbNfQBdZQBh':
path.d:(.text._D3std4path11expandTildeFNbNfAyaZ18expandFromDatabase
NbNfQBdZQBh+0x147): warning: Using 'getpwnam_r' in statically linked
applications requires at runtime the shared libraries from the glibc version
used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket25_sharedStaticCtor_L282_C1FZv':
socket.d:(.text._D3std6socket25_sharedStaticCtor_L282_C1FZv+0x14): warning:
Using 'getaddrinfo' in statically linked applications requires at runtime the
shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TkZQJwMFkZb':
socket.d:(.text._D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a20202020202020
0TkZQJwMFkZb+0x37): warning: Using 'gethostbyaddr' in statically linked
applications requires at runtime the shared libraries from the glibc version
used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020TAxaZQGpMFQjZb':
socket.d:(.text._D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020T
xaZQGpMFQjZb+0x43): warning: Using 'gethostbyname' in statically linked
applications requires at runtime the shared libraries from the glibc version
used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket8Protocol17getProtocolByTypeMFNbNeEQBuQBt12ProtocolTypeZb':
socket.d:(.text._D3std6socket8Protocol17getProtocolByTypeMFNbNeEQBuQBt12
rotocolTypeZb+0xa): warning: Using 'getprotobynumber' in statically linked
applications requires at runtime the shared libraries from the glibc version
used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket8Protocol17getProtocolByNameMFNbNeMAxaZb':
socket.d:(.text._D3std6socket8Protocol17getProtocolByNameMFNbNeMAxaZb+0x26):
warning: Using 'getprotobyname' in statically linked applications requires at
runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket7Service16getServiceByNameMFNbNeMAxaMQeZb':
socket.d:(.text._D3std6socket7Service16getServiceByNameMFNbNeMAxaMQeZb+0x57):
warning: Using 'getservbyname' in statically linked applications requires at
runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function 
`_D3std6socket7Service16getServiceByPortMFNbNetMAxaZb':
socket.d:(.text._D3std6socket7Service16getServiceByPortMFNbNetMAxaZb+0x30):
warning: Using 'getservbyport' in statically linked applications requires at
runtime the shared libraries from the glibc version used for linking
```

```
Thread 10 "twitchworker" received signal SIGSEGV, Segmentation 
fault.
[Switching to LWP 965536]
0x00007ffff7bd7ec0 in CONF_parse_list () from 
/opt/dell/dcc/libcrypto.so.3
(gdb) bt

/opt/dell/dcc/libcrypto.so.3

/opt/dell/dcc/libssl.so.3

/opt/dell/dcc/libssl.so.3

_D4arsd5http27OpenSSL__T10opDispatchVAyaa11_53534c5f4354585f6e6577Z__TQBuTPSQCwQCu10SSL_METHODZQCt
QzZPSQDyQDw7SSL_CTX (_param_0=0x7ffff7fb4620) at ../../.du
b/packages/arsd-official-10.9.2/arsd-official/http2.d:3592

_D4arsd5http213OpenSslSocket7initSslMFbAyaZv 
(this=0x7fffd603c060, verifyPeer=true, hostname="id.twitch.tv") 
at ../../.dub/packages/arsd-official-10.9.2/arsd
-official/http2.d:3806

_D4arsd5http213OpenSslSocket6__ctorMFE3std6socket13AddressFamilyEQBbQBa10Socke
TypeAyabZCQDjQDhQDe (this=0x7fffd603c060, af=std.socket.INET, type=std.socket.
STREAM, hostname="id.twitch.tv", verifyPeer=true) at 
../../.dub/packages/arsd-official-10.9.2/arsd-official/http2.d:3961
[...]
```

dmd seems to do this by default (`ldd` doesn't list any phobos or 
druntime .so files and program doesn't segfault), but I'm not 
sure how I can get ldc to behave the same. I looked over the 
`--help` listing but I could only find `--static` (and `--lib`, 
which I assume doesn't apply here).
Oct 25 2022
parent reply Kagamin <spam here.lot> writes:
ldc2 -link-defaultlib-shared=false or something like that
Oct 25 2022
parent Anonymouse <zorael gmail.com> writes:
On Tuesday, 25 October 2022 at 10:55:33 UTC, Kagamin wrote:
 ldc2 -link-defaultlib-shared=false or something like that
Thanks.
Oct 25 2022