Open justinas opened 3 days ago
v -cflags "-static" hello.v
Results in
$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=5218322b2e2cfe1833e376dff28d3a93ddf4c9be, for GNU/Linux 4.4.0, not stripped
v -cflags "-static" hello.v
Results in
$ file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=5218322b2e2cfe1833e376dff28d3a93ddf4c9be, for GNU/Linux 4.4.0, not stripped
Cool! It does work on Ubuntu. On NixOS, you need to have glibc.static
.
$ nix-shell -p glibc.static vlang
$ v -cflags -static hello.v
$ file ./hello
./hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.10.0, not stripped
$ ./hello
hello world
I still think that either this should be made the default, or the necessary flags clearly documented, or the claims about producing static binaries adjusted.
On another note, -cflags
will of course have no effect on the native backend, so eventually (once native backend is viable) something like a dedicated -static
flag will be necessary anyway.
I doubt it will be made the default, as it increases the file size by quite a bit...
[jalon@7950x ~]$ v hello.v
[jalon@7950x ~]$ ls -l hello
-rwxr-xr-x 1 jalon jalon 701432 Jun 29 15:56 hello
[jalon@7950x ~]$ v -cflags -static hello.v
[jalon@7950x ~]$ ls -l hello
-rwxr-xr-x 1 jalon jalon 1416784 Jun 29 15:56 hello
[jalon@7950x ~]$
... over twice as large output.
However, agreed that it could be made more obvious how to achieve statically linked binaries, and that it will also be necessary for a switch that works with the native backend... once that's actually working. :-)
Describe the bug
The V website claims that "You get a single statically linked binary". However, by default the compiler produces a dynamic binary, and there seems to be no way to produce a working static binary.
Reproduction Steps
Compile any code with V. Result is a dynamically linked binary.
Expected Behavior
Expected V to produce a statically linked binary.
Current Behavior
Compiling without any additional flags produces a dynamic binary:
Compiling with musl-gcc as suggested in https://github.com/vlang/v/discussions/19792#discussioncomment-7510933 does not work because pthreads fail to link:
Compiling with
-freestanding
as suggested by a Stack Overflow answer does produce a static binary, but it also makes V not link the C standard library at all (statically or dynamically). Since basic functionality of V depends on libc, this means that even basic code does not work out of the box in this mode:Possible Solution
V should either:
v -static
. V shouldn't lose basic functionality when the code is compiled this way.Additional Information/Context
No response
V version
V 0.4.6 4a7c70c
Environment details (OS name and version, etc.)