在x86_64机器上rust编译x86库

时间:2018-11-27 09:48:55

标签: rust cross-compiling rust-cargo

我有ubuntu x86_64容器,cargo build运行良好。 但是我也需要建立x86库版本。 据我了解,我需要添加i686工具链和目标。

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)

$ 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)

我错过了什么还是采取了错误的方法?

1 个答案:

答案 0 :(得分:1)

代替更改工具链,您必须将目标添加到当前工具链(请确保先切换回原始工具链)。

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

当然,您还需要在系统上安装32位库,例如在ubuntu上,您可以通过以下方式安装它们:

$ sudo apt install gcc-multilib

(有关详细信息,请参见How to Compile 32-bit Apps on 64-bit Ubuntu?

相关问题