segmentation-fault - 使用带有 Zig 的 X11 C 库时出现分段错误
问题描述
我正在尝试将 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
.
推荐阅读
- python - 如何使用 OpenCV 增加我的面罩检测项目的 FPS?
- django - Heroku 运行 python manage.py makemigartions --app=
正在抛出 ImproperlyConfigured:设置 DATABASE_NAME 环境变量 - javascript - React App 加载 HomePage 而不是 Desired Page
- ios - 为 C 库创建包装器以在 iOS 项目中使用
- c - 从行中删除前 n 个单词
- html - 如何使 Bootstrap v5.0 Carousel 滑块所有图像的高度相等
- javascript - 仅使用 php sparql 获取 wikidata 上存在的项目的标签
- sql - 在 blazor 中更改数据类型,然后在 SQL 中也会自动更改
- c++ - 如何在不使用静态成员函数`current`的情况下从函数中获取源位置作为参数?
- java - 为什么Mybatis Plus SqlSession总是会自动删除插入的数据?