简体   繁体   English

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

[英]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.

相关问题 在调试模式下构建Qt 5.10时,MSVC编译器崩溃 - MSVC compiler crashing when building Qt 5.10 in debug mode 如何在使用Visual C ++编译器在Windows上构建库时正确设置目标操作系统版本 - How to properly set target OS version when building a library on Windows using Visual C++ compiler 如何使用 system() 函数 (MSVC) 编译 C++ 代码? - How to compile c++ code with system() function (MSVC)? 从Java代码运行MSVC编译器会出现错误 - Running MSVC compiler from Java code gives error 使用make构建时,在c ++文件中概括include语句 - Generalizing include statements in c++ files when building with make 使用 cmake 和 msvc 构建 C++ - `/permissive-` 标志被删除 - building C++ with cmake and msvc - `/permissive-` flag gets dropped 如何在 C 编译器(mingw)(在 WINDOWS 上)中包含 curl 标头或库? - How to include curl header or library in C compiler(mingw)(on WINDOWS)? 如何将旧的 Visual C++ 代码 (vc++ 6.0) 转换为 Visual Studio 2019,缺少 libc - how to convert old visual c++ code (vc++ 6.0) to visual studio 2019, libc missing 使用MSVC 2010构建OpenSSL 1.0.1c时出错 - Error building OpenSSL 1.0.1c with MSVC 2010 如何在Windows上使用Vim运行“:compiler msvc”和“:comp msbuild”? - How to run “:compiler msvc” and “:comp msbuild” with Vim on Windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM