簡體   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