Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What functions is the libm intended for?

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?

like image 347
Alexey Avatar asked Jan 05 '19 18:01

Alexey


People also ask

What is LIBM used for?

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.

What is LIBM?

LIBM. Legislatively Infallible Business Model (economics)

What is LIBM in Linux?

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.

Where is LIBM so located?

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.


1 Answers

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.

like image 144
Florian Weimer Avatar answered Sep 23 '22 20:09

Florian Weimer