Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error loading target specification: Could not find specification for target

I'm following this tutorial on how to make an EXTREMELY BASIC Operating System in Rust. This is my current state:

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"
}

Here is the Makefile.


If you scroll down to the Fixing Linker Errors section in the tutorial, we're basically asked to add the following lines to our Cargo.toml:

[dependencies]
rlibc = "1.0"

Then specify the external crate in lib.rs (after the #![no_std]):

extern crate rlibc;

When I run make run in the terminal, I get the following error message:

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

error: Could not compile 'rlibc'

We're expected to get an error... just not this one. The example in the Fixing Linker Errors section gives an idea of the kind of error we should expect.

What may be going wrong? I've searched everywhere on Google with no solution.

like image 445
UndercoverCoder Avatar asked Jan 29 '23 23:01

UndercoverCoder


1 Answers

I had the same problem. These issues on Xargo and Cargo seem to suggest there's a bug about the location of target specs:

  • https://github.com/japaric/xargo/issues/44
  • https://github.com/rust-lang/cargo/issues/4865

Setting RUST_TARGET_PATH=pwd before invoking xargo fixed the issue for me. The invocation in the given Makefile will then look like this:

@RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target)
like image 130
Caligin Avatar answered Feb 03 '23 14:02

Caligin