As far as I know some math functions are contained in libc, while others are in libm. I've discovered that experimentally:
$ nm --dynamic --defined-only /lib/x86_64-linux-gnu/libm.so.6 | grep -w abs
$ nm --dynamic --defined-only /lib/x86_64-linux-gnu/libc.so.6 | grep -w abs
T abs
Is there a requirement concerning which mathematical functions must be provided by libm? Does libc and libm together provide all the math functions required by C standard?
LIBM is the standard C library of basic mathematical functions, such as sin(x), cos(x), exp(x), etc. To include the LIBM functions, just add -lm on your link command line. The Intel compiler includes an optimized math library that contains optimized implementations of LIBM functions.
LIBM. Legislatively Infallible Business Model (economics)
AOCL-LibM is a software library containing a collection of basic math functions optimized for x86-64 processor-based machines. It provides many routines from the list of standard C99 math functions.
The '../' in the file name gcc gave you means that you go up to the parent directory. So, libm is actually located at /usr/lib/x86_64-linux-gnu/libm.
Language standards such as ISO C and ISO C++ do not concern themselves with matters such as linking.
POSIX only requires that the c99
compiler supports -lm
, and that the functions declared in the headers <math.h>
, <complex.h>
and <fenv.h>
are available for linking if -lm
is specified. It is possible to meet this requirement if functions are defined in a library which is linked in by default.
With current glibc, the split of functions is mostly arbitrary, subject to a few limitations in the current implementation. (A long time ago, two threading libraries were supported, so all thread-related functionality had to go into libpthread
, but this is no longer the case.) Other approaches are possible: musl puts everything into libc.a
for static linking, and into the dynamic linker for dynamic linking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With