This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: printf more equal than sin?


On Wed, Oct 22, 2008 at 12:44 PM, Holger Blasum
<holger-r-glibc@blasum.net> wrote:
> the very elementary question I was asked by a friend and that I was not
> able to answer is: for the use of "sin"(math.h) I have to specify "-lm",
> for the use of "printf"(stdio.h) I have to specify nothing (when using gcc
> version 4.1.2 on i486-linux-gnu target). I acknowlegde the man page
> (man 3 sin) prominently says "Link with -lm" but that alone is not a very
> satisfying explanation.
>
> Where is it documented (in glibc sources, glibc documentation,
> gcc sources, binutils sources, the C standard or the ABI) for which
> functions of the standard library specifying nothing is ok (like
> "printf") and for which this is not ok (like: "sin" needing "-lm")?

To use printf you have to link in the C library e.g. -lc, but as a
convenience the compiler driver (gcc) does it for you.

gcc documents -nostartfile / -nodefaultlibs / -nostdlib as options
that control the automatic linking of system libraries.
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Link-Options.html#Link-Options

Since the compiler driver (gcc) does it for you, people get lazy and
omit the -lc from their build commands.

If you switch over to another compiler you might have to start adding -lc.

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]