rust - 使用no_std进行的 cargo 测试失败,错误代码为176、160

标签 rust rust-cargo rust-no-std

在main.rs中使用以下代码,当我运行cargo test时,在主函数中添加测试或`any语句时,它将返回错误代码176。它开始返回错误代码160。

#![no_std]
#![no_main]

#[cfg(test)]
#[macro_use]
extern crate std;
#[cfg(not(test))]
extern crate panic_halt;

#[no_mangle]
pub unsafe extern "C" fn main() {

}

从这个link我发现

Exit code 176 means "Unable to install on a network drive. Select another install location in your preferences and retry installing."



当我尝试通过lldb查找追溯时,它返回了

error: invalid thread



我找不到任何提及类似错误的线程,因此请在此处进行询问。
任何帮助表示赞赏。

每晚使用(nightly-x86_64-apple-darwin)
谢谢。

最佳答案

问题是您的main函数,该函数的unix平台签名无效。它必须返回一个i32(或更好的c_int,但为简单起见,我们假定它们是标识性的)。
离开176函数时,rax只是main寄存器中的一些随机值。

因此,将main签名更改为:

pub unsafe extern "C" fn main() -> i32

并返回一个返回码(例如0表示成功)

或者
pub unsafe extern "C" fn main() -> !

并在linux上使用exit syscall(或在嵌入式系统上使用无限循环)。

关于rust - 使用no_std进行的 cargo 测试失败,错误代码为176、160,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59410084/

相关文章:

rust - 如何访问特征的默认方法定义中的结构字段?

sockets - 如何设置 std::net::UdpSocket 超时?

rust - 我在哪里可以找到 .cargo/config?

rust - 在no_std环境中,我该如何替换Vec和HashSet?

rust - 有没有一种快速的方法来检查 Vec 是否有错误结果?

rust - `FnOnce` 的实现对于异步递归来说不够通用

rust - 是否可以使用夜间编译器编译一个特定的库,并将其链接到在稳定状态下编译的项目?

rust - 不能用箱子写 key 文件

arrays - 来自范围的常量数组

rust - 如何用重复的 u16 值填充 [u8] 数组?