rust compile x86 library on x86_64 machine

穿精又带淫゛_ 提交于 2021-02-19 09:45:29

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/53496847/rust-compile-x86-library-on-x86-64-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!