[4841] in Athena Bugs
cc
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Sun Apr 29 21:53:25 1990
Date: Sun, 29 Apr 90 21:53:08 -0400
From: "Jonathan I. Kamens" <jik@pit-manager.MIT.EDU>
To: agaminof@ATHENA.MIT.EDU
Cc: bugs@ATHENA.MIT.EDU
In-Reply-To: bugs[4840]
From: agaminof@ATHENA.MIT.EDU
Date: Sun, 29 Apr 90 21:42:48 -0400
Real-Name: Alex Aminoff
First of all, in the future, please use the "sendbug" program
whereever possible when reporting bugs, since this gives us the
information we need to correctly deal with your bug report.
cc -lm file.c breaks
cc file.c -lm works
Is this a bug or what?
No, it is not. Options such as "-lm" are passed on to the linker
program, "ld". Ld decides which files to pull out of an archive
("-lm" tells ld to look for the library "libm.a" in its library search
path) by figuring out which of the currently undefined symbols are
available in that archive; determination of undefined symbols and
searching of archives is done from left to right on the command line.
For example (using the commands you specified above), lets say that
the file "file.c" contains a reference to the function cos(), which
is in the math library. In the first case you mentioned, you're
telling ld to link the math library BEFORE it can possibly know that
file.c uses cos(), since file.c hasn't been linked yet. Therefore, it
doesn't link in the cos() function from the math library, and loses.
In the second case, first ld links file.c, and realizes that the
function cos() is used but not defined, and then checks for cos() in
the math library, since that's later on the command line.
Note that "breaks" and "works" are not adequate descriptions of the
problems you are having. When you are reporting a problem, please be
as specific as possible, including the error messages you got when
things worked. We didn't need them in this case, but we might in some
other situation.
Note also that it would have been good for you to ask about this in
olc before reporting it to bugs, especially since you don't appear to
be certain that it is a bug ("Is this a bug or what?").
Besides, the man page for cc makes no mention of -lm.
On which machine? Vax, RT, or MIPS? This is why we ask that you use
sendbug, which would provide this information for us automatically.
In any case, cc(1) and ld(1) don't mention "-lm" in particular,
because "-lm" is just one of many libraries. I believe that "man
math" would give you details about the math library in particular. In
addition, cc(1) doesn't mention the "-l" option, because, as I've
already stated, "-l" is an ld option, not a cc option. Cc(1) does
mention, "See ld(1) for load-time options."
In any case, thank you for taking the time to file a bug report, even
if it was not a bug in this particular case.
Jonathan Kamens
Project Athena Quality Assurance