Zig构建报错:无法打开URL路径的zig lib目录,求解决方案
如何直接通过URL引入Zig的rem库?
我尝试使用rem库,想把它直接通过URL添加到build.zig中,写了如下代码:
const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const path = std.build.LazyPath{ .path = "https://github.com/chadwain/rem.git" }; const exe = b.addExecutable({ .name = "html-txt", .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, .zig_lib_dir = path, }); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); // 允许用户在build命令中直接传递参数,例如:`zig build run -- arg1 arg2 etc` if (b.args) |args| { run_cmd.addArgs(args); } const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); }
但构建失败,报错如下:
$ zig build zig build-exe html-txt Debug native: error: error: unable to open zig lib directory 'https:/github.com/chadwain/rem.git': FileNotFound zig build-exe html-txt Debug native: error: the following command exited with error code 1: /usr/bin/zig build-exe /home/hasany/Documents/zig-tutorial/html-txt/src/main.zig --cache-dir /home/hasany/Documents/zig-tutorial/html-txt/zig-cache --global-cache-dir /home/hasany/.cache/zig --name html-txt --zig-lib-dir /home/hasany/Documents/zig-tutorial/html-txt/https:/github.com/chadwain/rem.git --listen=- Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none) install transitive failure └─ install html-txt transitive failure └─ zig build-exe html-txt Debug native failure error: the following build command failed with exit code 1: /home/hasany/Documents/zig-tutorial/html-txt/zig-cache/o/6e0a152f1b25945f81d097452bce1b34/build /usr/bin/zig /home/hasany/Documents/zig-tutorial/html-txt /home/hasany/Documents/zig-tutorial/html-txt/zig-cache /home/hasany/.cache/zig
我知道可以通过git clone https://github.com/chadwain/rem.git下载库后,用以下build.zig代码引入:
const std = @import("std"); pub fn build(b: *std.build.Builder) void { const target = b.standardTargetOptions(.{}); const optimize = .ReleaseFast; const exe = b.addExecutable({ .name = "myexe1", .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); const rem_src = "rem/rem.zig"; const rem_module = b.addModule("rem", .{ .source_file = .{ .path = rem_src }, }); exe.addModule("rem", rem_module); const run_step = b.step("run", "Run the app"); run_step.dependOn(&exe.step); }
但我希望找到直接使用URL路径引入该库的方法。
内容的提问来源于stack exchange,提问作者Hasan A Yousef
相关产品推荐
相关产品推荐

