If you use certain C functions, particularly math functions, the
compiler has to work a little harder to create an executable. To see
what I mean, take a look at ``sroot1.c'' in your ``examples'' directory
(or view it directly).
Notice that it uses the built-in function ``sqrt''. Now try to
compile it from Emacs, but before confirming the compilation command
delete the ``-lm'' from the end of the line. What happens?
Click here for the answer
The problem is that the compiler (more precisely, the linker) can't find the
compiled version of ``sqrt'' to link with your program. For most built-in C
functions, this kind of thing happens automatically. But if you want C to link
in any math functions, you must tell the linker to search the math library by
including the ``-lm'' option. By adding ``-lm'' you are telling the linker to
include the C math library functions.
If you continue to program in C, other situations will arise where you will
need to specify other library names to the linker. The math library is the
most frequently used, which is why it is always supplied--whether it is needed
or not--when compiling within Emacs.
Hamlet Project
hamlet@cs.utah.edu