-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rCore-Tutorial-Book-v3/chapter1/2remove-std #21
Comments
通过下面命令添加rust-std |
请问为何写了lang_items.rs后仍然提示 |
明白了,前面没有说要加入 mod lang_items |
使用清华网盘镜像里的Ubuntu时,加上#![no_std] 来告诉 Rust 编译器不使用 Rust 标准库 std后,报的错误和书里的有点不一样,我这儿的异常信息如下,请问还需要安装软件么? error: aborting due to previous error For more information about this error, try |
@leonhxx 请先输入以下命令安装一下相关软件: rustup target add riscv64gc-unknown-none-elf
cargo install cargo-binutils --vers ~0.2
rustup component add llvm-tools-preview
rustup component add rust-src |
@wyfcyx 多谢呀!! |
error: language item required, but not found: error: aborting due to previous error error: could not compile |
@eulerf 请按照这里所提到的:
进行交叉编译,避免编译到x86目标。 |
你好这个我已经照做了创建了config文件
…------------------ 原始邮件 ------------------
发件人: "Yifan ***@***.***>;
发送时间: 2021年5月4日(星期二) 下午4:26
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [rcore-os/rCore-Tutorial-Book-v3] rCore-Tutorial-Book-v3/chapter1/2remove-std (#21)
@eulerf 请按照这里所提到的:
我们首先在 os 目录下新建 .cargo 目录,并在这个目录下创建 config 文件,并在里面输入如下内容:
# os/.cargo/config [build] target = "riscv64gc-unknown-none-elf"
进行交叉编译,避免编译到x86目标。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
谢谢已经改正成功了
…------------------ 原始邮件 ------------------
发件人: "Yifan ***@***.***>;
发送时间: 2021年5月4日(星期二) 下午4:26
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [rcore-os/rCore-Tutorial-Book-v3] rCore-Tutorial-Book-v3/chapter1/2remove-std (#21)
@eulerf 请按照这里所提到的:
我们首先在 os 目录下新建 .cargo 目录,并在这个目录下创建 config 文件,并在里面输入如下内容:
# os/.cargo/config [build] target = "riscv64gc-unknown-none-elf"
进行交叉编译,避免编译到x86目标。
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
如果你在src写入了lang_items.rs 仍然会有panic_handler的错误,请在main.rs中写入如下语句 main.rs: #![no_std] mod lang_items; fn main() { 然后就可以继续执行了 |
Rust的mod是不是相当于C语言的include |
@wei-huan 差不多吧。 |
Entry入口不等于0,反汇编也是有对应代码的,跟教程不一致,请问是什么原因呢 ➜ os git:(master) ✗ cat src/main.rs
#![no_std]
#![no_main]
mod lang_items;
➜ os git:(master) ✗ cat src/lang_items.rs
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
➜ os git:(master) ✗ rust-readobj -h target/riscv64gc-unknown-none-elf/debug/os
File: target/riscv64gc-unknown-none-elf/debug/os
Format: elf64-littleriscv
Arch: riscv64
AddressSize: 64bit
LoadName: <Not found>
ElfHeader {
Ident {
Magic: (7F 45 4C 46)
Class: 64-bit (0x2)
DataEncoding: LittleEndian (0x1)
FileVersion: 1
OS/ABI: SystemV (0x0)
ABIVersion: 0
Unused: (00 00 00 00 00 00 00)
}
Type: Executable (0x2)
Machine: EM_RISCV (0xF3)
Version: 1
Entry: 0x11120
ProgramHeaderOffset: 0x40
SectionHeaderOffset: 0x11C0
Flags [ (0x5)
EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
EF_RISCV_RVC (0x1)
]
HeaderSize: 64
ProgramHeaderEntrySize: 56
ProgramHeaderCount: 4
SectionHeaderEntrySize: 64
SectionHeaderCount: 15
StringTableSectionIndex: 13
}
➜ os git:(master) ✗ rust-objdump -S target/riscv64gc-unknown-none-elf/debug/os
target/riscv64gc-unknown-none-elf/debug/os: file format elf64-littleriscv
Disassembly of section .text:
0000000000011120 <rust_begin_unwind>:
; fn panic(_info: &PanicInfo) -> ! {
11120: 41 11 addi sp, sp, -16
11122: 2a e4 sd a0, 8(sp)
11124: 09 a0 j 0x11126 <rust_begin_unwind+0x6>
; loop {}
11126: 01 a0 j 0x11126 <rust_begin_unwind+0x6> |
补充:vscode上如果加上 |
Q:为何在 main.rs中要加入 |
希望能在“我们创建一个新的子模块 lang_items.rs 实现panic函数......编译器用panic函数来对接 panic! 宏:”的位置添上“并在main.rs 然后把下面的Rust Tips:Rust 模块化编程的链接贴一个在附近。 |
@iruhh 好主意。 |
不起作用。我的配置: {
"rust.target": "riscv64gc-unknown-none-elf",
"rust.all_targets": false,
"rust-analyzer.cargo-watch.allTargets": false,
"rust-analyzer.cargo-watch.arguments": [
"--target",
"riscv64gc-unknown-none-elf"
]
} 使用的插件:两个都试过,都不行。 错误信息:
|
@pluveto ,将 {
"rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.checkOnSave.target": "riscv64gc-unknown-none-elf"
} 之后 vscode 就没有报错了。 |
对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在 {
"cargo.automaticCheck": false
} 对于此错误的猜想,我也是从这里获取的灵感:rust-lang/rust-analyzer#3801 (comment) |
在 "rust-analyzer.checkOnSave.allTargets": false, 可避免问题。 |
噗哈哈哈哈, 写了个寂寞, 全删掉了🤣 |
依照在本章最后,换回之前默认的 x86_64-unknown-linux-gnu,
|
楼主文档写得很详细也比较容易看懂,但是代码能不能加点注释 |
he@ubuntu: 那个反汇编工具用不了啊 |
如果你在src写入了lang_items.rs 仍然会有panic_handler的错误,请在main.rs中写入如下语句 main.rs: #![no_std] mod lang_items; fn main() { 然后就可以继续执行了 这里的main.rs:的冒号报错了 |
对照博客做吧,三元组不一样,不是改一个参数就能解决掉的。(虽然改动确实也不大) |
对于 error[E0463]: can't find crate for test 问题,可以将 rust-analyzer.check.allTargets 设置为 false。在设置界面修改或写入 setting.json 文件都可以。 另外,这是在 os 目录下有 .cargo/config 文件注明了 target,如果没有此文件,可能还需加入 target。 |
确实是cargo插件的问题,一个巨坑 {
"cargo.automaticCheck": false
} 这行东西最新版本好像没有用,我的选择是直接删除cargo插件 |
我取消了config中的[build]设置,也就是切换到了x86_64-unknown-linux-gnu,按照blogOS的教程在cargo.toml中添加了如下代码,禁用多处 panic! 栈展开
在这之后遇到了linker cc error
Done! |
添加 # Cargo.toml
[package]
name = "xxx"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "xxx"
test = false
bench = false
[dependencies] |
移除标准库依赖 — rCore-Tutorial-Book-v3 0.1 文档
https://rcore-os.github.io/rCore-Tutorial-Book-v3/chapter1/2remove-std.html
The text was updated successfully, but these errors were encountered: