This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: printf more equal than sin?
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: "Holger Blasum" <holger-r-glibc at blasum dot net>
- Cc: libc-help at sourceware dot org
- Date: Wed, 22 Oct 2008 15:37:55 -0400
- Subject: Re: printf more equal than sin?
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=36J/5NQQtp/3QgaHL0q7tUe06uJBN7gzR27w7SRdh+8=; b=abt8xQ0pt2YoaX5S8icXyUN/XhGqoEJpSTGjP5Z7y2dfhtd9d2FptJM+eZnjBTJCsf eDExrnqiE44ywrYdLg5IE2YTxsw95OkhYQq05BLsLcnrYspHE0i9gTGo4eCLEuBIVMXU utWJShg61dtnraOP6SKNDzz69YovPv+FIwkIQ=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=h34JEWN6hZ7KhoD0+U3C4hskfOOaIkHoUBiEocqFhJOjWt5prWpzS9wTdShxHoqK2A VbbSte9GeEM4P7QR7xfCJxjgF/YsKZpz9MQ/7XgTJFZDbk+G5gVn7FIWVptku+x3lmSr FENqxSgx9rmxLn3po4PWRUsmHNolyvGvxK3W0=
- References: <20081022164449.GA19622@koretsu>
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.