我正在尝试将 microUI 库从 C 移植到 zig。
我曾尝试使用此端口尝试https://gitdab.com/luna/zig-microui作为指南,但它似乎不起作用。
到目前为止,这是我尝试的细分:
MicroUI 是一个非常简单的程序,由一个 .h 文件和一个 .c 文件组成。这两个文件都位于我的项目根目录下的文件夹“./microui”下。
我的 build.zig:
const std = @import("std");
const c_args = [_][]const u8{
"-Wall",
"-std=c11",
"-pedantic",
// prevent sigill
"-fno-sanitize=undefined",
};
pub fn build(b: *std.build.Builder) void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("ZigMicroUI", "src/main.zig");
lib.linkSystemLibrary("c");
lib.linkLibC();
lib.addIncludeDir("./microui");
lib.addCSourceFile("microui/microui.c", &c_args);
lib.setBuildMode(mode);
lib.install();
var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
}
c.zig:
pub usingnamespace @cImport({
@cInclude("microui.h");
});
main.zig 的相关部分:
const std = @import("std");
const testing = std.testing;
const c = @import("c.zig");
export fn begin_window() void {
const ctx: c.mu_Context = null;
}
'zig build test' 的输出:
.\src\c.zig:1:20: error: C import failed
pub usingnamespace @cImport({
^
.\src\c.zig:1:20: note: libc headers not available; compilation does not link against libc
pub usingnamespace @cImport({
^
.\zig-cache\o\013eb3e1efd6fe219480e321f33592ae\cimport.h:1:10: note: 'microui.h' file not found
#include <microui.h>
^
.\src\main.zig:6:16: error: container 'c' has no member called 'mu_Context'
const ctx: c.mu_Context = null;
如果有人可以提供帮助,我觉得这一定是我想念的小东西。