The C library is not a single library file. It is composed of four main parts that together implement the POSIX functions API:
libc
: The main C library that contains the well-known POSIX functions such asprintf
,open
,close
,read
,write
, and so onlibm
: Maths functions such ascos
,exp
, andlog
libpthread
: All the POSIX thread functions with names beginning withpthread_
librt
: The real-time extensions to POSIX, including shared memory and asynchronous I/O
The first one, libc
, is always linked in but the others have to be explicitly linked with the -l
option. The parameter to -l
is the library name with lib
stripped off. So, for example, a program that calculates a sine function by calling sin()
would be linked with libm
using -lm
:
arm-cortex_a8-linux-gnueabihf-gcc myprog.c -o myprog -lm
You can verify which libraries have been linked in this or any other program by using the readelf
command:
$ arm-cortex_a8-linux-gnueabihf-readelf -a myprog | grep...