0182-独立可执行程序

环境

  • Time 2022-11-12
  • WSL-Ubuntu 22.04
  • QEMU 6.2.0
  • Rust 1.65.0

前言

说明

参考:https://os.phil-opp.com/freestanding-rust-binary

目标

当前为新的篇章,参考的原文第二版,和之前的第一版不关联。
使用 Rust 编写一个独立可执行程序,即不依赖操作系统的程序。
其中的概念和错误的解决方式可以参考原文,有中文翻译。

main.rs

#![no_std]
#![no_main]

#[no_mangle]
pub extern "C" fn _start() -> ! {
    loop {}
}

#[cfg(not(test))] // 避免 vscode 提示错误
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

Cargo.toml

[package]
name = "mos"
version = "0.1.0"
edition = "2021"

[dependencies]


[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

编译

root@jiangbo12490:~/git/game# cargo build --target thumbv7em-none-eabihf
   Compiling mos v0.1.0 (/root/git/game)
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s

总结

使用 Rust 编写了一个独立可执行程序。

附录

posted @   jiangbo4444  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-07-15 【JavaScript】事件介绍
点击右上角即可分享
微信分享提示