将X11 C库与Zig一起使用时出现细分错误

问题描述

我正在尝试将X11与Zig一起使用。以https://rosettacode.org/wiki/Window_creation/X11#Xlib中的代码为例,我想到了这个最小的例子:

const c = @cImport({
    @cInclude("X11/Xlib.h");
});

pub fn main() void {
    var maybe_display : ?*c.Display = c.XOpenDisplay(@as(?*u8,null));
}

使用最新版本的Zig(0.6.0)进行编译:

zig build-exe -lX11 main.zig

执行时出现以下错误:

Segmentation fault at address 0x0
attempt to unwrap error: InvalidExe
Panicked during a panic. Aborting.
fish: './main' terminated by signal SIGABRT (Abort)

解决方法

您可能还需要链接到libc。尝试添加-lc

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...