3

I have ubuntu x86_64 container and cargo build goes well. But i need to build x86 library version too. As far as I understand i need to add i686 toolchain and target.

rustup target add i686-unknown-linux-gnu done successful
rustup toolchain install stable-i686-unknown-linux-gnu finished with error
$ rustup toolchain install stable-i686-unknown-linux-gnu
info: syncing channel updates for 'stable-i686-unknown-linux-gnu'
info: latest update on 2018-11-08, rust version 1.30.1 (1433507eb 2018-11-07)
info: downloading component 'rustc'
info: downloading component 'rust-std'
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'

  stable-i686-unknown-linux-gnu installed - (error reading rustc version)

and

$ rustup  default stable-i686
info: using existing install for 'stable-i686-unknown-linux-gnu'
info: default toolchain set to 'stable-i686-unknown-linux-gnu'

  stable-i686-unknown-linux-gnu unchanged - (error reading rustc version)

Do I missed something or took wrong approach?

2 Answers 2

4

Instead of changing your toolchain, you have to add the target to your current toolchain (make sure to switch back to your original toolchain first).

$ rustup target install i686-unknown-linux-gnu
$ cargo build --target=i686-unknown-linux-gnu

Of course, you need to install the 32-bit libraries on your system as well, e.g. on ubuntu you install them by

$ sudo apt install gcc-multilib

(for more information about that see How to Compile 32-bit Apps on 64-bit Ubuntu?)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. It was helpful. but I got stuck with the next step. error: failed to run custom build command for openssl-sys v0.9.39 Problem with x86_64 build I solved by installing libssl-dev But installing libssl-dev:i386 did not solve error on crosscompile. btw it is not Ubuntu i have. Debian stretch
The full error message would be helpful (and maybe worth another question).
Problem resolved by pointing OPENSSL_DIR to right place. Yes, i should make a new question for it. Thank you
0

Bottom link is a great article. Also cargo make everything so easy.

cargo new --bin rust
     Created binary (application) `rust` package

cd rust
cargo run

   Compiling rust v0.1.0 (/home/user/Documents/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.37s
     Running `target/debug/rust`
Hello, world!

cat ~/.cargo/config
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /home/user/.cargo/config
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [target.x86_64-unknown-linux-musl]
   2   │ linker = "x86_64-linux-gnu-gcc"
   3   │ 
   4   │ [target.x86_64-unknown-linux-gnu]
   5   │ linker = "x86_64-linux-gnu-gcc"
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

cargo run
   Compiling rust v0.1.0 (/home/user/Documents/rust)
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/rust`
I love programming.

cargo build --release --target x86_64-unknown-linux-musl
   Compiling rust v0.1.0 (/home/user/Documents/rust)
    Finished release [optimized] target(s) in 0.31s

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.