GCC -lm -lz -lrt options - what are they about?

妖精的绣舞 提交于 2020-01-01 07:34:31

问题


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 is this one - -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?

回答1:


  • -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



回答2:


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




回答3:


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.




回答4:


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++).




回答5:


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.

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 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.



来源:https://stackoverflow.com/questions/5663097/gcc-lm-lz-lrt-options-what-are-they-about

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