[Courses] Reminder, and questions (and semi spoiler on ex 6-1)

Sonja Krause-Harder skh at addcom.de
Mon Feb 25 20:09:34 EST 2002


On Mon, Feb 25, 2002 at 08:54:21AM -0500, Michelle Murrain wrote:
 
> On compiling, it barfs with this error:
> /home/mpm/tmp/ccU4dc3d.o: In function `main':
> /home/mpm/code/cprograms/ex6-1.c:26: undefined reference to `sqrt'
> collect2: ld returned 1 exit status

You have to tell the linker (ld) explicitly to use the math library,
where all functions defined in math.h are implemented. On linux,
you do this by giving gcc the additional parameter '-lm' on the
command line (l for library and m probably for math :)), so the
command to compile a one-file example is:

   $ gcc -o example -lm example.c

That should do it -

kind regards

Sonja (who had to look that one up as well)



More information about the Courses mailing list