windows - 用 Rust 构建的 DLL 在运行时需要 libgcc.dll 吗?

标签 windows rust libgcc

如果我用 Rust language 构建一个 DLL , 它是否需要 libgcc*.dll 在运行时出现?

一方面:

  • 我在互联网上的某个地方看到过一个帖子,声称是的;
  • rustc.exe 在其目录中有 libgcc_s_dw2-1.dll,下载后 cargo.exe 没有 dll 将无法运行来自 http://crates.io网站;

另一方面:

  • 我看过有关使用 Rust 构建玩具操作系统内核的文章,因此它们肯定不需要 libgcc 动态库。

所以,我很困惑。什么是确定的答案?

最佳答案

Rust 为 Windows 提供了两个主要的工具链:x86_64-pc-windows-gnux86_64-pc-windows-msvc

-gnu 工具链包括一个msys 环境并使用GCC 的ld.exe 链接目标文件。此工具链要求 libgcc*.dll 在运行时存在。这个工具链的主要优点是它允许您链接到其他 msys 提供的库,这样可以更容易地链接到某些在正常 Windows 环境下难以链接的 C\C++ 库。

-msvc 工具链使用标准的本地 Windows 开发工具(Windows SDK 安装或 Visual Studio 安装)。此工具链在编译或运行时不使用 libgcc*.dll。由于此工具链使用普通的 Windows 链接器,您可以自由链接任何普通的 Windows native 库。

如果您需要针对 32 位 Windows,可以使用这两个工具链的 i686- 变体。


注意:下面的回答总结了截至 2014 年 9 月的情况;我不知道它是否仍然是最新的,或者从那时起事情是否变得更好或更糟。但我强烈怀疑情况已经发生了变化,因为从那时起已经过去了 2 年。如果有人试图再次询问 steveklabnik,然后更新下面的信息,或者写一个新的、更新的答案,那就太好了!


与 steveklabnik 的 Rust IRC 聊天的快速原始记录,他给了我一个答案:

Hi; I have a question: if I build a DLL with Rust, does it require libgcc*.dll to be present on run time? (on Windows)

相信如果您使用标准库,那么它确实需要它; IIRC 我们依赖于它的一个符号; 但我不确定。

How can I avoid using the standard library, or those parts of it that do? (and/or do you know which symbol exactly?)

它涉及到你的 crate root 中的#[no_std];我想the unsafe guide还有更多。

运行 nm -D | grep gcc 显示了 __gc_personality_v0,然后是:What is __gxx_personality_v0 for? , 所以看起来我们的堆栈展开实现取决于此。

I seem to recall I've seen some RFCs to the effect of splitting standard library, too; are there parts I can use without pulling libgcc in?

是的,libcore 不需要任何这些。 您放弃 libstd

此外,引用 the unsafe guide 的部分内容:

The core library (libcore) has very few dependencies and is much more portable than the standard library (libstd) itself. Additionally, the core library has most of the necessary functionality for writing idiomatic and effective Rust code. (...) Further libraries, such as liballoc, add functionality to libcore which make other platform-specific assumptions, but continue to be more portable than the standard library itself.

当前的和片段docs for unwind module :

Currently Rust uses unwind runtime provided by libgcc.

(为了便于阅读,对文字记录进行了轻微编辑。不过,如果有人提供格式更好、更全面的内容,我会很乐意删除这个答案!)

关于windows - 用 Rust 构建的 DLL 在运行时需要 libgcc.dll 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26064673/

相关文章:

windows - 任务列表未检测/支持超过 21 个字符的进程名称

windows - 在 Windows 中使用 OpenAI API key 时出现问题

windows - 获取 "netsh dhcp server ..."命令的输出

rust - 如何从主泛型推论出子泛型?

c - 将 libgcc 链接到 -nostdlib 编译

windows - 有没有一种方法可以在批处理脚本中存储和检索文件中的密码?

c++ - 在对C++程序进行反向工程时,如何将std::basic_string <char>转换为Rust可读的值?

rust - 如何在实现 Deref 的类型(例如 Box)内对值进行模式匹配,而不复制内容?

c++ - libgcc_s.so 在同一进程中静态和动态链接是否正常?

c++ - gcc 无效版本(最大)错误添加符号 : Bad value