Jac*_*123 3 c++ build-tools go toolchain rust
rustc foo.rs如果我没有安装C ++工具链,则使用编译Rust文件将失败。但是在编译Go程序时,不需要这样的工具链。这是为什么?
Mat*_* M. 12
TL;DR: Because everyone has a C toolchain.
Slight correction: rustc does not require a C++ toolchain, it only requires a C toolchain. Notably, rustc created binaries only depend on libc (or equivalent), not on libstdc++ (or equivalent).
As Go demonstrated, it is possible to not require a C toolchain. You only need to re-implement its functionality:
There are advantages to doing so, such as possibly faster compilation or easier cross-compiling, however there is a cost in doing the implementation, and it's easy to get things wrong.
The Rust community preferred to put more effort into the language than in the toolchain, and therefore reusing the stock toolchain was easier. Specifically, rustc will require a platform linker (ld on Unix) and platform equivalent to libc.
This is not a core design principle, it's just a pragmatic approach, and there are projects to cut down on these dependencies:
libcAPI 的可移植Rust实现)。这些都在进行中,与此同时,rustc需要C工具链。此外,即使在可预见的将来,我也希望rustc对于尚未被任何Rust工具链覆盖的目标要求使用C工具链,这样您就可以使用目标而无需等待任何假想的开发。