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

后端 未结 5 1031
猫巷女王i
猫巷女王i 2021-02-12 13:36

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 st

相关标签:
5条回答
  • 2021-02-12 14:07

    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.

    0 讨论(0)
  • 2021-02-12 14:11
    • -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
    0 讨论(0)
  • 2021-02-12 14:13

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

    0 讨论(0)
  • 2021-02-12 14:15

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

    0 讨论(0)
  • 2021-02-12 14:17

    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.

    0 讨论(0)
提交回复
热议问题