I'm trying to build a project for x86_64-unknown-linux-none, but I get this error:
error[E0463]: can't find crate for `std`
|
= note: the `x86_64-unknown-linux-none` target may not be installed
= help: consider downloading the target with `rustup target add x86_64-unknown-linux-none`
So I started following the compiler instructions to no avail:
~/Projekte/rcon-rs> rustup target add x86_64-unknown-linux-none
error: toolchain 'stable-x86_64-unknown-linux-gnu' does not support target 'x86_64-unknown-linux-none'; did you mean 'x86_64-unknown-linux-gnu'?
note: you can see a list of supported targets with `rustc --print=target-list`
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html
~/Projekte/rcon-rs>
~/Projekte/rcon-rs> rustup target add x86_64-unknown-linux-none -- --force-non-host
error: toolchain 'stable-x86_64-unknown-linux-gnu' does not support target 'x86_64-unknown-linux-none'; did you mean 'x86_64-unknown-linux-gnu'?
note: you can see a list of supported targets with `rustc --print=target-list`
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html
~/Projekte/rcon-rs> rustup toolchain install stable-x86_64-unknown-linux-none
error: toolchain 'stable-x86_64-unknown-linux-none' may not be able to run on this system
note: to build software for that platform, try `rustup target add x86_64-unknown-linux-none` instead
note: add the `--force-non-host` flag to install the toolchain anyway
~/Projekte/rcon-rs> rustup toolchain install stable-x86_64-unknown-linux-none --force-non-host
info: syncing channel updates for 'stable-x86_64-unknown-linux-none'
info: latest update on 2025-04-03, rust version 1.86.0 (05f9846f8 2025-03-31)
error: target 'x86_64-unknown-linux-none' not found in channel. Perhaps check https://doc.rust-lang.org/nightly/rustc/platform-support.html for available targets
~/Projekte/rcon-rs> rustc --print=target-list | grep x86_64-unknown-linux-none
x86_64-unknown-linux-none
~/Projekte/rcon-rs>
Which rustc version do you have installed? rustc -vV
Edit: Never mind. You were looking for x86_64-unknown-linux-none, not x86_64-unknown-none. x86_64-unknown-linux-none is a tier 3 target. This means that there are no precompiled versions of it's standard library available. Instead you have to use nightly and build with cargo build -Zbuild-std --target x86_64-unknown-linux-none to have cargo build the standard library for you.
This target has no support for host tools, std, or alloc.
You can’t install it through rustup since it doesn’t have precompiled artifacts:
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will need to … build your own copy of core by using build-std or similar.
You need to use #![no_std] and use -Z build-std=core. If you want to use std, you need a libc.
Is there a config option for that in .cargo/config.toml?
I tried to throw it into the rustflags array to no avail:
~/helloworld> cat .cargo/config.toml
[build]
build-stage = 1
target = ["x86_64-unknown-linux-none"]
#rustflags = ["-Zbuild-std"]
~/helloworld> cargo +nightly build -Zbuild-std
warning: unused config key `build.build-stage` in `/home/rne/helloworld/.cargo/config.toml`
Compiling helloworld v0.1.0 (/home/rne/helloworld)
error[E0463]: can't find crate for `std`
|
= note: the `x86_64-unknown-linux-none` target may not support the standard library
= note: `std` is required by `helloworld` because it does not declare `#![no_std]`
= help: consider building the standard library from source with `cargo build -Zbuild-std`
error: `#[panic_handler]` function required, but not found
For more information about this error, try `rustc --explain E0463`.
error: could not compile `helloworld` (bin "helloworld") due to 2 previous errors
~/helloworld> cat .cargo/config.toml
[build]
build-stage = 1
target = ["x86_64-unknown-linux-none"]
rustflags = ["-Zbuild-std"]
~/helloworld> cargo +nightly build
warning: unused config key `build.build-stage` in `/home/rne/helloworld/.cargo/config.toml`
error: failed to run `rustc` to learn about target-specific information
Caused by:
process didn't exit successfully: `/home/rne/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -Zbuild-std --target x86_64-unknown-linux-none --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg -Wwarnings` (exit status: 1)
--- stderr
error: unknown unstable option: `build-std`
~/helloworld>