Windows crate包含编译好的静态库的原因是什么?

huangapple go评论85阅读模式
英文:

Why does the Windows crate contain compiled static libraries?

问题

以下是翻译好的部分:

"The windows crate, which provides Rust bindings to the Windows API, is split into a few internal crates, one of them being the windows-targets. This create is also split in a few internal crates, and these are loaded according to the target platform."

这个句子描述了提供 Rust 绑定到 Windows API 的 windows crate,它被分为几个内部 crate 之一是 windows-targets。windows-targets 也分为一些内部 crate,根据目标平台进行加载。

"These platform-dependent crates don't seem to do much: they simply pass cargo:rustc-link-search=native={LIB_DIR} to the compiler."

这些依赖于平台的 crate 似乎并没有做太多事情:它们只是将 cargo:rustc-link-search=native={LIB_DIR} 传递给编译器。

"Now looking at these LIB_DIR directories, they contain an already-compiled static library, one for each platform. Example: windows.0.48.0.lib file."

现在查看这些 LIB_DIR 目录,它们包含了一个已经编译好的静态库,每个平台一个。例如:windows.0.48.0.lib 文件。

"I couldn't find any documentation regarding this, but I suppose these static libraries are compiled from the C source files found in the baseline directory, which contain... a duplication of the Windows API function declarations in C. That's intriguing."

我找不到关于这一点的任何文档,但我猜想这些静态库是从在 baseline 目录中找到的 C 源文件编译而来的,这些文件中包含了 Windows API 函数声明的重复。这很有趣。

"The Rust bindings themselves are written somewhere else, like here (GDI bindings)."

Rust 绑定本身是在其他地方编写的,比如在这里(GDI 绑定)。

Question: these compiled C static libraries seem to be a duplication of the API already available in Windows, so why are they necessary?
问题: 这些编译的 C 静态库似乎是对已经在 Windows 中可用的 API 的重复,那么它们为什么是必要的?

英文:

The windows crate, which provides Rust bindings to the Windows API, is split into a few internal crates, one of them being the windows-targets. This create is also split in a few internal crates, and these are loaded according to the target platform.

These platform-dependent crates don't seem to do much: they simply pass cargo:rustc-link-search=native={LIB_DIR} to the compiler.

Now looking at these LIB_DIR directories, they contain an already-compiled static library, one for each platform. Example: windows.0.48.0.lib file.

I couldn't find any documentation regarding this, but I suppose these static libraries are compiled from the C source files found in the baseline directory, which contain... a duplication of the Windows API function declarations in C. That's intriguing.

The Rust bindings themselves are written somewhere else, like here (GDI bindings).

Question: these compiled C static libraries seem to be a duplication of the API already available in Windows, so why are they necessary?

答案1

得分: 1

我通过直接询问官方Windows Crate维护者获得了回应:

虽然GNU和MSVC工具链通常提供一些导入库以支持C++开发,但这些库文件经常不完整、缺失或者只是错误的。这可能导致非常难以诊断的链接器错误。windows-targets Crate 确保可以链接由 windowswindows-sys Crates 定义的所有函数,而无需依赖工具链分发的隐式库文件。

如有兴趣,更多详细信息可以在这里查看。

英文:

I got a response by asking directly the official windows crate maintainers:

> While the GNU and MSVC toolchains often provide some import libs to support C++ development, those lib files are often incomplete, missing, or just plain wrong. This can lead to linker errors that are very difficult to diagnose. The windows-targets crate ensures that all functions defined by the windows and windows-sys crates can be linked without relying on implicit lib files distributed by the toolchain.

For anyone interested, further details can be seen here.

huangapple
  • 本文由 发表于 2023年4月11日 00:34:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978884.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定