我正在为一个不支持std或alloc的平台编写Rust代码,所以我只能使用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编译器告诉我为什么需要全局内存分配器?据推测,在我的代码或依赖项中的某个地方,有什么东西试图分配,这导致它出错,但我不知道这是在哪里发生的.
对于这种情况,我在网上看到的唯一建议是创建一个虚拟自定义分配器,然后查看编译后的二进制文件以获取对它的引用.然而,我这样做了,但在它生成的二进制可执行文件中找不到任何对我的自定义分配器的引用,这让我对正在发生的事情更加困惑.