[英]How to include (msvc) libc when building c code with the Zig compiler
I've recently discovered zig and find it very interesting.我最近发现了 zig 并发现它非常有趣。 I'm now trying to learn how to use zig as a cross compiler and, the following builds and runs fine (on Windows)
我现在正在尝试学习如何使用 zig 作为交叉编译器,并且以下构建和运行良好(在 Windows 上)
zig cc -Wno-everything src/ctest.c
however, when I use the build-exe command or build script, the (Windows) libc cannot be found and linked但是,当我使用 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")
...
If I could see what zig cc really does, maybe I could figure it out (but zig cc does not seem to allow the --verbose-cc flag).如果我能看到 zig cc 真正做了什么,也许我可以弄清楚(但 zig cc 似乎不允许 --verbose-cc 标志)。 Or how can I get zig to link with msvc (or any other working libc) on Windows?
或者如何让 zig 与 Windows 上的 msvc(或任何其他工作 libc)链接? For completeness, the build.zig script is effectively:
为了完整起见, 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);
...
Here's the relevant issue for this: https://github.com/ziglang/zig/issues/514这是与此相关的问题: https : //github.com/ziglang/zig/issues/514
Once the Windows libc portion of this issue is implemented, your example will work.一旦实现了此问题的 Windows libc 部分,您的示例将起作用。 Until then, cross compiling for Windows code that wants to link libc would need a cross compiling environment.
在此之前,为想要链接 libc 的 Windows 代码进行交叉编译将需要一个交叉编译环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.