When using gcc
under Linux, one does not need to add command-line options to use standard library functions like printf
. In book An Introduction to GCC, it explains "The C standard library itself is stored in ‘/usr/lib/libc.a’ and contains functions specified in the
ANSI/ISO C standard, such as ‘printf’—this library is linked by default for every C program."
But one has to add -lm
in the command-line to use standard library functions declared in math.h
, since libm.a
is not linked against in default.
So which standard library functions are included in libc.a
, thus do not require to link other library files. And other than libm.a
, are there any other standard library functions that need to explicitly add library files to link against, and what are the file names of the library?
Asked
Active
Viewed 7,317 times
6

WiSaGaN
- 46,887
- 10
- 54
- 88
-
1You can use the nm command to find out what a library contains. – Jim Balter Aug 13 '12 at 02:46
-
@JimBalter Is there a way to get better results than just a pile of object symbols? – WiSaGaN Aug 13 '12 at 03:07
-
Select defined external symbols. But really, you don't need that ... libc.a contains everything except those things that are explicitly stated to need another library. – Jim Balter Aug 13 '12 at 03:14
1 Answers
2
libc
and libm
both handle all ANSI/ISO functions. Beyond that, Linux and UNIX systems follow POSIX, which includes libpthread
(usually linked in using the -pthread
option, not explicitly linking in the library), as well as libiconv
which may be included in libc
. Additional libraries in POSIX include curses
and libutil
for miscellaneous functions.

chmeee
- 3,608
- 1
- 21
- 28