Comments (31)
明白了,前面没有说要加入 mod lang_items
from rcore-tutorial-book-v3.
如果你在src写入了lang_items.rs 仍然会有panic_handler的错误,请在main.rs中写入如下语句
mod lang_items;
main.rs:
#![no_std]
mod lang_items;
fn main() {
// println!("Hello, world!");
}
然后就可以继续执行了
from rcore-tutorial-book-v3.
@pluveto ,将 rust-analyzer.checkOnSave.target
设置为 riscv64gc-unknown-none-elf
就可以了:
{
"rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.checkOnSave.target": "riscv64gc-unknown-none-elf"
}
之后 vscode 就没有报错了。
from rcore-tutorial-book-v3.
@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
from rcore-tutorial-book-v3.
补充:vscode上如果加上#[no_std]
提示cann't find crate for test
refer
from rcore-tutorial-book-v3.
通过下面命令添加rust-std
rustup target add riscv64gc-unknown-none-elf
from rcore-tutorial-book-v3.
请问为何写了lang_items.rs后仍然提示
error: #[panic_handler]
function required, but not found呢?
(用的是前面配好的docker环境)
from rcore-tutorial-book-v3.
@wei-huan 差不多吧。
from rcore-tutorial-book-v3.
补充:vscode上如果加上
#[no_std]
提示cann't find crate for test
refer不起作用。我的配置:
{ "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" ] }使用的插件:两个都试过,都不行。
错误信息:
can't find crate for `test`
对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在 settings.json
加入以下配置
{
"cargo.automaticCheck": false
}
对于此错误的猜想,我也是从这里获取的灵感:rust-lang/rust-analyzer#3801 (comment)
from rcore-tutorial-book-v3.
使用清华网盘镜像里的Ubuntu时,加上#![no_std] 来告诉 Rust 编译器不使用 Rust 标准库 std后,报的错误和书里的有点不一样,我这儿的异常信息如下,请问还需要安装软件么?
error[E0463]: can't find crate for core
|
= note: the riscv64gc-unknown-none-elf
target may not be installed
error: aborting due to previous error
For more information about this error, try rustc --explain E0463
.
error: could not compile os
from rcore-tutorial-book-v3.
@wyfcyx 多谢呀!!
from rcore-tutorial-book-v3.
error: language item required, but not found: eh_personality
error: aborting due to previous error
error: could not compile Os
你好我照着做以后出现这个报错是为什么呢?
from rcore-tutorial-book-v3.
@eulerf 请按照这里所提到的:
我们首先在
os
目录下新建.cargo
目录,并在这个目录下创建config
文件,并在里面输入如下内容:# os/.cargo/config [build] target = "riscv64gc-unknown-none-elf"
进行交叉编译,避免编译到x86目标。
from rcore-tutorial-book-v3.
from rcore-tutorial-book-v3.
from rcore-tutorial-book-v3.
Rust的mod是不是相当于C语言的include
from rcore-tutorial-book-v3.
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>
from rcore-tutorial-book-v3.
Q:为何在 main.rs中要加入 mod lang_items;
这条语句?
A: 由于os是 no_std程序,所以没法调用panic!等属于rust std库中的宏。从ch1开始,我们就写了 lang_items.rs , 实现了自己的panic!宏,这就是你指出的 mod lang_items; 表示 main.rs 要调用的panic!,将是自己在写的lang_items.rs中的panic!宏。
from rcore-tutorial-book-v3.
希望能在“我们创建一个新的子模块 lang_items.rs 实现panic函数......编译器用panic函数来对接 panic! 宏:”的位置添上“并在main.rs #![no_std]
的下方加上mod lang_items;
来声明模块”
然后把下面的Rust Tips:Rust 模块化编程的链接贴一个在附近。
from rcore-tutorial-book-v3.
@iruhh 好主意。
from rcore-tutorial-book-v3.
补充:vscode上如果加上
#[no_std]
提示cann't find crate for test
refer
不起作用。我的配置:
{
"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"
]
}
使用的插件:两个都试过,都不行。
错误信息:
can't find crate for `test`
from rcore-tutorial-book-v3.
补充:vscode上如果加上
#[no_std]
提示cann't find crate for test
refer不起作用。我的配置:
{ "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" ] }使用的插件:两个都试过,都不行。
错误信息:can't find crate for `test`
对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在
settings.json
加入以下配置{ "cargo.automaticCheck": false }对于此错误的猜想,我也是从这里获取的灵感:rust-analyzer/rust-analyzer#3801 (comment)
在 nvim.coc
中使用 rust-analyzer 时,在CoC配置中写入:
"rust-analyzer.checkOnSave.allTargets": false,
可避免问题。
from rcore-tutorial-book-v3.
噗哈哈哈哈, 写了个寂寞, 全删掉了🤣
from rcore-tutorial-book-v3.
依照在本章最后,换回之前默认的 x86_64-unknown-linux-gnu,cargo build
以后,有一个报错始终出现
error: language item required, but not found: `eh_personality`
|
= note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
= help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`
error: `#[panic_handler]` function required, but not found
from rcore-tutorial-book-v3.
楼主文档写得很详细也比较容易看懂,但是代码能不能加点注释
from rcore-tutorial-book-v3.
he@ubuntu:/C_TEST/os$ rust-objdump -S target/riscv64gc-unknown-none-elf/debug/os/C_TEST/os$ rust-readobj -h target/riscv64gc-unknown-none-elf/debug/os
Failed to execute tool: objdump
No such file or directory (os error 2)
he@ubuntu:
Failed to execute tool: readobj
No such file or directory (os error 2)
那个反汇编工具用不了啊
from rcore-tutorial-book-v3.
如果你在src写入了lang_items.rs 仍然会有panic_handler的错误,请在main.rs中写入如下语句
mod lang_items;
main.rs:
#![no_std]
mod lang_items;
fn main() {
// println!("Hello, world!");
}
然后就可以继续执行了
这里的main.rs:的冒号报错了
from rcore-tutorial-book-v3.
依照在本章最后,换回之前默认的 x86_64-unknown-linux-gnu,
cargo build
以后,有一个报错始终出现error: language item required, but not found: `eh_personality` | = note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library = help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config` error: `#[panic_handler]` function required, but not found
对照博客做吧,三元组不一样,不是改一个参数就能解决掉的。(虽然改动确实也不大)
from rcore-tutorial-book-v3.
对于 error[E0463]: can't find crate for test 问题,可以将 rust-analyzer.check.allTargets 设置为 false。在设置界面修改或写入 setting.json 文件都可以。
另外,这是在 os 目录下有 .cargo/config 文件注明了 target,如果没有此文件,可能还需加入 target。
比如,"rust-analyzer.cargo.target": "riscv64imac-unknown-none-elf",
from rcore-tutorial-book-v3.
补充:vscode上如果加上
#[no_std]
提示cann't find crate for test
refer不起作用。我的配置:
{ "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" ] }使用的插件:两个都试过,都不行。
错误信息:can't find crate for `test`
对于此报错,还有一种可能是 cargo 插件的自动检查导致的,可在
settings.json
加入以下配置{ "cargo.automaticCheck": false }对于此错误的猜想,我也是从这里获取的灵感:rust-lang/rust-analyzer#3801 (comment)
确实是cargo插件的问题,一个巨坑
{
"cargo.automaticCheck": false
}
这行东西最新版本好像没有用,我的选择是直接删除cargo插件
from rcore-tutorial-book-v3.
我取消了config中的[build]设置,也就是切换到了x86_64-unknown-linux-gnu,按照blogOS的教程在cargo.toml中添加了如下代码,禁用多处 panic! 栈展开
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
在这之后遇到了linker cc error
原因大概是在这样的三元组链接条件下,linux上的c库需要找到入口函数
但是我们没有:(
因此使用如下命令 成功完成build
cargo rustc -- -C link-arg=-nostartfiles
Done!
from rcore-tutorial-book-v3.
Related Issues (20)
- 我想在user_lib中syscall的部分对Read操作增加枚举 HOT 1
- rCore-Tutorial-Book-v3/chapter8/4condition-variable HOT 1
- rCore-Tutorial-Book-v3/chapter8/5concurrency-problem HOT 4
- rCore-Tutorial-Book-v3/chapter0/8answer HOT 1
- ch4-lab无法编译成功 HOT 4
- rCore-Tutorial-Book-v3/chapter0/7exercise
- rCore-Tutorial-Book-v3/chapter4/9answer HOT 7
- rCore-Tutorial-Book-v3/chapter7/3cmdargs-and-redirection HOT 2
- 1. 运行完第一个用户程序之后,run_next_app()函数是被什么东西调用的?。进入_restore之后,匹配到的是用户申请的trap,不会运行run_next_app
- 建议将本书中部分”同学“字样 修改成 ”同学们“
- ch9: 2device-driver-3 成员变量 `avail_idx` 是可用环索引
- ch8: 用户态的线程管理一节 spawn 方法中 s_ptr.offset(32) 问题
- rCore-Tutorial-Book-v3/appendix-d/1asm HOT 1
- rCore-Tutorial-Book-v3/chapter9/2device-driver-0 HOT 4
- 代码仓RustSBI兼容性适配的对应文档更新
- rCore-Tutorial-Book-v3/chapter9/2device-driver-4 HOT 2
- rCore-Tutorial-Book-v3/chapter9/5answer HOT 1
- 优化调度算法一节的描述并修复错误
- 一些功能与内容方面的建议 HOT 4
- 新增基于vscode的devcontainer插件,利用docker配置环境的相关说明
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rcore-tutorial-book-v3.