我知道这些是一些常见/基本的库,但它们到底意味着什么?
例如,我知道 -lm
是某个数学库,但这是标准数学库还是什么?
-lz
用于压缩?什么压缩?
我不知道 -lrt
是什么。
这些是什么东西?
- 数学图书馆。当我们包含
或
时使用的内容是否相同?
- 压缩库。这意味着什么?它是否提供了一些我们可以用来压缩文件的工具,或者它是否帮助编译器/链接器做一些压缩的事情?
I know that these are some common/basic libraries, but what do they mean exactly?
For example, I know, that -lm
is some math library, but is this the standard math library or what?
-lz
for compression? What compression?
And I don't have any idea what -lrt
is.
What are these things?
- math library. Is it the same that we use when we include
<cmath>
or <math.h>
?
- compress library. What does this mean? Does it provide some tools that we can use to compress files, or does it help the compiler/linker to do some compress things?
发布评论
评论(5)
-lz
- 是 zlib,http://zlib.net/-lm
- 是您已经制定的数学库(据我所知实现定义)-lrt
- 提供 POSIX 实时扩展: http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?librt+ 3LIB-lz
- is zlib, http://zlib.net/-lm
- is the math library as you've worked out (implementation defined AFAIK)-lrt
- provides POSIX realtime extensions: http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?librt+3LIB开关 -lX 通常表示加载库 libX.so。
libm 是标准数学库;它包含 sin()、cos()、atanh(),所有这些好东西。
libz 是 Zlib,一个压缩库,可以执行 gzip、deflate 和其他一些格式。
有几个不同的 librt:一个是 POSIX 实时扩展;另一个是 POSIX 实时扩展。另一个是通用编程辅助工具库。
The switch -lX generally means to load the library libX.so.
libm is the standard math library; it contains sin(), cos(), atanh(), all that good stuff.
libz is Zlib, a compression library which can do gzip, deflate, and a few other formats.
There are a couple of different librt's out there: one is the POSIX realtime extensions; another is a library of general-purpose programming aids.
-lz 链接到 zlib,-lm 链接到 数学 和 -lrt 到 实时扩展库。
-lz links to the zlib, -lm to the math and -lrt to the realtime extensions library.
libm
libz
librt
所有这些据我所知,是标准 C,可能包含在 libstdc++ 中(你的问题被标记为 C++)。
libm
libz
librt
All of them are standard C as far as I know, probably included in libstdc++ (your question is tagged C++).
前面的答案都是正确的。作为一名 C 新手,我要补充的一件事是
-l
参数告诉编译器将您的代码与某个库链接。对我和其他人来说,令人困惑的是,调用
-l
加上库名称时没有空格。所以-lz
,您正在链接到“z”。请注意,这些库已安装在您的系统中。它们要么随您正在使用的发行版一起提供,要么您使用包管理器安装或从源(
make
、make install
...)。由于这些是非常基本(且旧)的库 API,因此它们的名称非常短。当您在系统中安装特定库时,您会看到更多详细名称标记
-l
。The previous answers are all correct. The one thing I would add, being a C novice myself, is that the
-l
argument tells the compiler to link your code with some library.The confusion for me and probably others is that there is no space when calling the
-l
plus the name of the lib. so-lz
, you are linking to the "z".Note that these libraries are installed in your system. Either they came with the distribution you are using, or you installed using a package manager or compiled from source (
make
,make install
...).Since those are very basic (and old) library APIs, they have very short names. As you progress and install specific libraries in your system, you see more verbose names tagging the
-l
there.