加载目标规范时出错:无法找到目标规范

问题描述 投票:3回答:1

我正在关注this tutorial如何在Rust中制作一个极其基本的操作系统。这是我目前的状态:

Cargo.toml

[package]
name = "blog_os"
version = "0.1.0"
authors = ["Philipp Oppermann <[email protected]>"]   # Here I used my own details

[lib]
crate-type = ["staticlib"]

SRC / lib.rs

#![feature(lang_items)]
#![no_std]

#[no_mangle]
pub extern fn rust_main() {}

#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] #[no_mangle] pub extern fn panic_fmt() -> ! {loop{}}

x86_64的-blog_os.json

{
  "llvm-target": "x86_64-unknown-none",
  "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
  "linker-flavor": "gcc",
  "target-endian": "little",
  "target-pointer-width": "64",
  "target-c-int-width": "32",
  "arch": "x86_64",
  "os": "none",
  "disable-redzone": true,
  "features": "-mmx,-sse,+soft-float"
}

这是Makefile


如果向下滚动到教程中的Fixing Linker Errors部分,我们基本上要求将以下行添加到Cargo.toml

[dependencies]
rlibc = "1.0"

然后在lib.rs中指定外部包(在#![no_std]之后):

extern crate rlibc;

当我在终端中运行make run时,我收到以下错误消息:

error: Error loading specification: Could not find specification for target "x86_64-blog_os" 

error: Could not compile 'rlibc'

我们预计会出现错误...而不是这个错误。 “修复链接器错误”部分中的示例提供了我们应该期望的错误类型的概念。

可能出现什么问题?我在谷歌的任何地方搜索都没有解决方案。

rust linker-errors rlib
1个回答
6
投票

我有同样的问题。 Xargo和Cargo上的这些问题似乎表明目标规范的位置有一个错误:

在调用RUST_TARGET_PATH=pwd之前设置xargo为我解决了这个问题。给定Makefile中的调用将如下所示:

@RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target)
© www.soinside.com 2019 - 2024. All rights reserved.