Open gshanemiller opened 1 year ago
Workaround is to use LD_PRELOAD
to run the executable and link only when running it, as in
LD_PRELOAD="/usr/lib64/libpthread.so.0 /usr/lib64/libdl.so.2 /usr/lib64/libc.so.6" zig-out/bin/<program-name>
You can check the linkage with
LD_PRELOAD="/usr/lib64/libpthread.so.0 /usr/lib64/libdl.so.2" ldd zig-out/bin/zLBM
linux-vdso.so.1 (0x00007f9e96424000)
/usr/lib64/libpthread.so.0 (0x00007f9e96419000)
/usr/lib64/libdl.so.2 (0x00007f9e96414000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9e96214000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9e96426000)
You may want to try reproducing again with a newer Zig release. For example a glibc build failure with zig in releases earlier than 0.12.0
was the cause of this one: https://github.com/rust-cross/cargo-zigbuild/issues/255#issuecomment-2339632373
That said zig cc
still fails with building a static binary, even when .a
files are provided it still has an interpreter configured for some reason 🤷♂️ (resulting in a segfault) https://github.com/ziglang/zig/issues/4986#issuecomment-1982362679
Zig Version
0.11.0-dev.1987+a2c6ecd6d Ubuntu 22.04LTS
Steps to Reproduce and Observed Behavior
This bug might be related to https://github.com/ziglang/zig/issues/14963
As with vanilla C development, Zig should be able to link against standard shared libraries (e.g. pthread.so, mlx5.so, ibverbs.so). I cannot make this happen. I've played over several hours with CompileStep's options to no avail.
Although static link is generally preferred, in this case I want these libraries linked dynamically. No matter what I do, all successful builds give:
ldd
does not showlibibverbs
, for example. I'm pretty sure Zig linked statically; regardless the behavior of the program is wrong. See below.To reproduce:
stdout reports:
It should report (2) devices not 0.
Expected Behavior
Since the ZIG build does not work and does not produce the correct output, I'll give the expected output by showing what a C build of the same two
.c
files gives when built by gcc:The zig code is a cannon shooting a fly. All it does is call a single C function
ibv_get_device_list
. A relevant difference between the correct behavior and Zig is how this symbol is linked: