繁体   English   中英

使用 Zig 编译器构建 c 代码时如何包含 (msvc) libc

[英]How to include (msvc) libc when building c code with the Zig compiler

我最近发现了 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);
...

这是与此相关的问题: https : //github.com/ziglang/zig/issues/514

一旦实现了此问题的 Windows libc 部分,您的示例将起作用。 在此之前,为想要链接 libc 的 Windows 代码进行交叉编译将需要一个交叉编译环境。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM