GCC -lm -lz -lrt选项 - 它们是关于什么的?

时间:2022-07-02 04:54:28

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?

例如,我知道,-lm是一些数学库,但这是标准的数学库还是什么?

-lz for compression? What compression?

-lz用于压缩?什么压缩?

And I don't have any idea what is this one - -lrt.

我不知道这是什么 - -lrt。


Can someone specify these things:

有人可以指定这些东西:

  • math library - the same that we use when we include <cmath> or <math.h>?
  • 数学库 - 我们在包含 时使用的相同?

  • compress library - what does this mean - provides some tools, that we can use to compress files, or helps the compiler/linker to do some compress-things?
  • 压缩库 - 这意味着什么 - 提供了一些我们可以用来压缩文件的工具,或者帮助编译器/链接器做一些压缩工作?

5 个解决方案

#1


20  

  • -lz - is zlib, http://zlib.net/
  • -lz - 是zlib,http://zlib.net/

  • -lm - is the math library as you've worked out (implementation defined AFAIK)
  • -lm - 是你已经解决的数学库(实现定义了AFAIK)

  • -lrt- provides POSIX realtime extensions: http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?librt+3LIB
  • -lrt-提供POSIX实时扩展:http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?librt +3LIB

#2


3  

-lz links to the zlib, -lm to the math and -lrt to the realtime extensions library.

-lz链接到zlib,-lm链接到数学,-lrt链接到实时扩展库。

#3


2  

The switch -lX generally means to load the library libX.so.

交换机-lX通常意味着加载库libX.so.

libm is the standard math library; it contains sin(), cos(), atanh(), all that good stuff.

libm是标准的数学库;它包含sin(),cos(),atanh(),所有这些好东西。

libz is Zlib, a compression library which can do gzip, deflate, and a few other formats.

libz是Zlib,一个压缩库,可以执行gzip,deflate和其他一些格式。

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.

有一些不同的librt:一个是POSIX实时扩展;另一个是通用编程辅助工具库。

#4


1  

libm http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/libm.html

libz http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/libzman.html

librt http://www.rdg.ac.uk:8081/cgi-bin/cgiwrap/wsi14/poplog/man/3LIB/librt

All of them are standard C afaik, probably included in libstdc++ (your question is tagged C++).

所有这些都是标准的C afaik,可能包含在libstdc ++中(您的问题标记为C ++)。

#5


0  

The answers above 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.

上面的答案都是正确的。我要添加的一件事,就是我自己的C新手,是-l参数告诉编译器将你的代码链接到某个库。

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"

对我和可能是其他人的困惑是,在调用-l加上lib的名称时没有空间。所以-lz,你链接到“z”

Note that these libraries are installed in your system. Either they came with the distro 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 libs in your system, you see more verbose names tagging the -l there.

请注意,这些库安装在您的系统中。要么他们带有您正在使用的发行版,要么使用包管理器安装或从源代码编译(make,make install ...)。由于这些是非常基本的(和旧的)库APIS,因此它们的名称非常短。当您在系统中进行并安装特定的库时,您会看到更多详细的名称标记-l。

#1


20  

  • -lz - is zlib, http://zlib.net/
  • -lz - 是zlib,http://zlib.net/

  • -lm - is the math library as you've worked out (implementation defined AFAIK)
  • -lm - 是你已经解决的数学库(实现定义了AFAIK)

  • -lrt- provides POSIX realtime extensions: http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?librt+3LIB
  • -lrt-提供POSIX实时扩展:http://www.s-gms.ms.edus.si/cgi-bin/man-cgi?librt +3LIB

#2


3  

-lz links to the zlib, -lm to the math and -lrt to the realtime extensions library.

-lz链接到zlib,-lm链接到数学,-lrt链接到实时扩展库。

#3


2  

The switch -lX generally means to load the library libX.so.

交换机-lX通常意味着加载库libX.so.

libm is the standard math library; it contains sin(), cos(), atanh(), all that good stuff.

libm是标准的数学库;它包含sin(),cos(),atanh(),所有这些好东西。

libz is Zlib, a compression library which can do gzip, deflate, and a few other formats.

libz是Zlib,一个压缩库,可以执行gzip,deflate和其他一些格式。

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.

有一些不同的librt:一个是POSIX实时扩展;另一个是通用编程辅助工具库。

#4


1  

libm http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/libm.html

libz http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/libzman.html

librt http://www.rdg.ac.uk:8081/cgi-bin/cgiwrap/wsi14/poplog/man/3LIB/librt

All of them are standard C afaik, probably included in libstdc++ (your question is tagged C++).

所有这些都是标准的C afaik,可能包含在libstdc ++中(您的问题标记为C ++)。

#5


0  

The answers above 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.

上面的答案都是正确的。我要添加的一件事,就是我自己的C新手,是-l参数告诉编译器将你的代码链接到某个库。

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"

对我和可能是其他人的困惑是,在调用-l加上lib的名称时没有空间。所以-lz,你链接到“z”

Note that these libraries are installed in your system. Either they came with the distro 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 libs in your system, you see more verbose names tagging the -l there.

请注意,这些库安装在您的系统中。要么他们带有您正在使用的发行版,要么使用包管理器安装或从源代码编译(make,make install ...)。由于这些是非常基本的(和旧的)库APIS,因此它们的名称非常短。当您在系统中进行并安装特定的库时,您会看到更多详细的名称标记-l。