板条箱中的 "library" 到底是什么?
What exactly is a "library" in a crate?
我对rust中的“库”这个概念有点困惑,这个概念在“A crate is a binary or library”中提到过。
如果我是对的,二进制表示可执行程序(例如,可以是 shell 中的 运行),但什么是库?
它们是某种带有 .a 或 .so 等符号的目标文件吗,它们将链接到我的程序(如 C/C++)
或者是纯源代码,会和我的程序一起编译?
If I'm right, a binary means an executable program (which can be run from shell, for example), but what is a library?
是的。具体来说,根据 the Linkage documentation
A runnable executable will be produced. This requires that there is a main function in the crate which will be run when the program begins executing. This will link in all Rust and native dependencies, producing a single distributable binary. This is the default crate type.
Are they some sort of object files with symbols like .a or .so, which will be linked to my program (like C/C++)
Or they are pure source codes which will be compiled together with my program?
绝对不是后者,但确切的人工制品取决于链接文档:
A Rust library will be produced. This is an ambiguous concept as to what exactly is produced because a library can manifest itself in several forms. The purpose of this generic lib option is to generate the "compiler recommended" style of library. The output library will always be usable by rustc, but the actual type of library may change from time-to-time.
文档然后列出了各种类型的库:
- rlib,一个带有 Rust 特定元数据的静态库(一个增强的 .a)
- dylib,一个带有 Rust 特定元数据的动态库(一个增强的 .so)
- staticlib,一个系统静态库(一个实际的.a)
- cdylib,一个系统动态库(一个实际的.so)
我认为“lib”是“rlib”的别名,但坦率地说,我不知道,正如引用所指出的那样,设计。
正如 Masklinn 所描述的,是的,Rust 确实有预构建的库格式。但是,这些主要在内部使用,对于不同的编译器版本来说很费力,而且 cargo still lacks support for them。事实上,crates.io 要求库是“开源”的(例如,你提供源代码,你仍然可以从一些封闭源依赖项中加载源代码),并将源代码分发到谁下载了箱子。然后,源代码会有效地与您的程序一起编译(这是 rlibs 发挥作用的地方,但 cargo 不会将其暴露给用户)。这也是为什么您能够检查几乎每个 crate 的源代码的原因。
我对rust中的“库”这个概念有点困惑,这个概念在“A crate is a binary or library”中提到过。
如果我是对的,二进制表示可执行程序(例如,可以是 shell 中的 运行),但什么是库?
它们是某种带有 .a 或 .so 等符号的目标文件吗,它们将链接到我的程序(如 C/C++)
或者是纯源代码,会和我的程序一起编译?
If I'm right, a binary means an executable program (which can be run from shell, for example), but what is a library?
是的。具体来说,根据 the Linkage documentation
A runnable executable will be produced. This requires that there is a main function in the crate which will be run when the program begins executing. This will link in all Rust and native dependencies, producing a single distributable binary. This is the default crate type.
Are they some sort of object files with symbols like .a or .so, which will be linked to my program (like C/C++)
Or they are pure source codes which will be compiled together with my program?
绝对不是后者,但确切的人工制品取决于链接文档:
A Rust library will be produced. This is an ambiguous concept as to what exactly is produced because a library can manifest itself in several forms. The purpose of this generic lib option is to generate the "compiler recommended" style of library. The output library will always be usable by rustc, but the actual type of library may change from time-to-time.
文档然后列出了各种类型的库:
- rlib,一个带有 Rust 特定元数据的静态库(一个增强的 .a)
- dylib,一个带有 Rust 特定元数据的动态库(一个增强的 .so)
- staticlib,一个系统静态库(一个实际的.a)
- cdylib,一个系统动态库(一个实际的.so)
我认为“lib”是“rlib”的别名,但坦率地说,我不知道,正如引用所指出的那样,设计。
正如 Masklinn 所描述的,是的,Rust 确实有预构建的库格式。但是,这些主要在内部使用,对于不同的编译器版本来说很费力,而且 cargo still lacks support for them。事实上,crates.io 要求库是“开源”的(例如,你提供源代码,你仍然可以从一些封闭源依赖项中加载源代码),并将源代码分发到谁下载了箱子。然后,源代码会有效地与您的程序一起编译(这是 rlibs 发挥作用的地方,但 cargo 不会将其暴露给用户)。这也是为什么您能够检查几乎每个 crate 的源代码的原因。