Open slaide opened 5 years ago
Can I see xcb.zig and (gdb) disassemble
after the segfault?
When trying to reproduce this I found that this segfaults when the user forgets to link to libc (--library c
).
Working command: zig build-exe main.zig -isystem /usr/include -L /usr/lib/ --library xcb --library c
Zig file (main.zig):
const xcb = @cImport(@cInclude("xcb/xcb.h"));
pub fn main() void {
var connection = xcb.xcb_connect(null, null);
}
Edit: When doing zig translate-c /usr/include/xcb/xcb.h
on the file without --library c
it correctly gives an error about a <sys/types.h> file that cannot be found. However this error is not shown when doing the zig build-exe command without --library c
Edit2: The same fault happens when a user makes a build.zig file and only adds exe.linkSystemLibrary("xcb")
and doesn't add exe.linkSystemLibrary("c")
. One could imagine that the zig user doesn't know that they have to link to libc.
I don't think there is a lot Zig can do here. Adding -lxcb
also adds all the import directories needed for it so no error is produced. Same thing happens with translate-c
if you add -lxcb
.
for no apparent reason, a call to xcb_connect causes a segfault (on linux x86_64). exactly the same code succeeds in c++. i do include the same file, link to the same library, and open the file the same way (also built in the same environment, etc.). absolutely no clue what the problem is.
zig version: 0.4.0+c5716715
valgrind: