我最近发现了 zig,发现它非常有趣。我现在正在尝试学习如何使用 zig 作为交叉编译器,并且以下构建和运行良好(在 Windows 上)
zig cc -Wno-everything src/ctest.c
但是,当我使用 build-exe 命令或构建脚本时,无法找到和链接 (Windows) libc
c:\zigctest>zig build
Zig is unable to provide a libc for the chosen target 'x86_64-unknown-windows-msvc'.
The target is non-native, so Zig also cannot use the native libc installation.
Choose a target which has a libc available, or provide a libc installation text file.
See `zig libc --help` for more details.
The following command exited with error code 1:
c:\zigctest\zig.exe build-exe --library c --c-source -Wno-everything C:\zigctest\src\ctest.c --cache-dir C:\zigctest\zig-cache --name ctest -target x86_64-windows-msvc --cache on
exec failed
C:\zigctest\lib\zig\std\build.zig:768:36: 0x7ff76fece654 in std.build.Builder::std.build.Builder.exec (build.obj)
std.debug.panic("exec failed")
...
如果我能看到 zig cc 的真正作用,也许我可以弄清楚(但 zig cc 似乎不允许 --verbose-cc 标志)。或者我怎样才能让 zig 与 Windows 上的 msvc(或任何其他工作的 libc)链接?为了完整起见, build.zig 脚本实际上是:
...
const cflags = [][]const u8{
"-Wno-everything",
};
const exe = b.addExecutable("ctest", null);
exe.linkSystemLibrary("c");
exe.setBuildMode(mode);
exe.setTarget(builtin.Arch.x86_64, .windows, .msvc);
exe.addCSourceFile("src/ctest.c",cflags);
...