You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
$ cat hello.vfn main() { println("hello world")}
$ v hello.v
$ file hellohello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, not stripped
Compiling with musl-gcc as suggested in #19792 (comment) does not work because pthreads fail to link:
$ v -cc musl-gcc -cg hello.v/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `open_proc_fd':gc.c:(.text+0x13a7): undefined reference to `__snprintf_chk'/usr/bin/ld: gc.c:(.text+0x13ba): undefined reference to `__open_2'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_fault_handler':gc.c:(.text+0x14aa): undefined reference to `__longjmp_chk'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_with_callee_saves_pushed':gc.c:(.text+0x2f2c): undefined reference to `getcontext'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_printf':gc.c:(.text+0x420a): undefined reference to `__vsnprintf_chk'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_log_printf':gc.c:(.text+0x4867): undefined reference to `__vsnprintf_chk'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_err_printf':gc.c:(.text+0x79f4): undefined reference to `__vsnprintf_chk'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_print_callers':gc.c:(.text+0x7c54): undefined reference to `__snprintf_chk'/usr/bin/ld: gc.c:(.text+0x7cef): undefined reference to `__snprintf_chk'/usr/bin/ld: gc.c:(.text+0x7d36): undefined reference to `__memcpy_chk'/usr/bin/ld: gc.c:(.text+0x7e64): undefined reference to `__snprintf_chk'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_print_all_errors.part.0':gc.c:(.text+0x826e): undefined reference to `__memcpy_chk'/usr/bin/ld: gc.c:(.text+0x828a): undefined reference to `__memset_chk'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(gc.o): in function `GC_init':gc.c:(.text+0xf53e): undefined reference to `gnu_get_libc_version'/usr/bin/ld: /home/justinas/vlang-box/compiler/thirdparty/tcc/lib/libgc.a(pthread_start.o): in function `GC_pthread_start_inner':pthread_start.c:(.text+0x82): undefined reference to `__pthread_register_cancel'/usr/bin/ld: pthread_start.c:(.text+0xa9): undefined reference to `__pthread_unregister_cancel'collect2: error: ld returned 1 exit statusbuilder error:==================C error found. It should never happen, when compiling pure V code.This is a V compiler bug, please report it using `v bug file.v`,or goto https://github.com/vlang/v/issues/new/choose .You can also use #help on Discord: https://discord.gg/vlang .
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:
$ cat array.vfn main() { mut foo := [1, 2, 3] foo.sort() println(foo)}
$ v -freestanding array.v
$ file arrayarray: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=19986c1fa887f421581deb1982106b06a5a33ee6, not stripped
$ ./arrayV panicsort does not work with -freestanding
Possible Solution
V should either:
Output static binaries by default, since that is the claim on the front page.
Provide a dedicated, well documented flag that would link the resulting binary statically instead of dynamically, e.g. v -static. V shouldn't lose basic functionality when the code is compiled this way.
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 #19792 (comment) does not work because pthreads fail to link:
Compiling with
-freestandingas 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.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.