RUST NO_STD查找为什么需要全局内存分配器

发布于 2025-02-11 12:07:06 字数 511 浏览 1 评论 0原文

我正在为不支持性病或Alloc的平台编写Rust Code,因此我只需使用Core。最近,我的代码已经开始产生此编译错误:

error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait

error: `#[alloc_error_handler]` function required, but not found

有没有办法让Rust编译器告诉我为什么需要全局内存分配器?据推测,我的代码或依赖关系中的某个地方试图分配某些东西,这导致了它出错,但我无法弄清楚这发生在哪里。

我在网上看到这种情况的唯一建议是制作虚拟自定义分配器,然后浏览编译的二进制文件以获取参考。但是,我这样做了,无法在其产生的二进制执行中找到对我的自定义分配器的任何引用,这使我对正在发生的事情更加困惑。

I'm writing Rust code for a platform which doesn't have support for std or alloc, so I have to use only core. Recently, my code has started producing this compile error:

error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait

error: `#[alloc_error_handler]` function required, but not found

Is there a way I can get the rust compiler to tell me why a global memory allocator is required? Presumably, somewhere in my code or my dependencies something is attempting to allocate and that's causing it to go wrong, but I can't figure out where this is happening.

The only advice I saw online for this situation is to make a dummy custom allocator and then look through the compiled binary for references to it. However, I did this and am unable to find any reference to my custom allocator in the binary executable that it produced, which is making me more confused as to what's going on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路终见情 2025-02-18 12:07:06

就我的情况而言,它努力使用货物供应商将我所有依赖项的源源下载到本地目录中,然后我使用RIPGREP来搜索依赖项extern Crate alloc; <<<<<<<extern crate; <<<<< /code>,这导致我在不知情的情况下进行了分配的依赖项之一。我不知道为什么分配没有在生成的二进制中显示,但是这个工具比实施虚拟分配器更好。

For my case, it worked to use cargo vendor to download the source for all of my dependencies into a local directory, and then I used ripgrep to search through the dependencies for extern crate alloc;, which led me to one of my dependencies allocating without my knowledge. I don't know why the allocations didn't show up in the resulting binary, but this tool led me to the cause better than implementing a dummy allocator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文