Complete.Org: Mailing Lists: Archives: linux-help: August 2002:
[linux-help] Re: A c problem
Home

[linux-help] Re: A c problem

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: linux-help@xxxxxxxxx
Subject: [linux-help] Re: A c problem
From: Steven Saner <ssaner@xxxxxxxxxxxxxxx>
Date: Mon, 5 Aug 2002 15:33:28 -0500
Reply-to: linux-help@xxxxxxxxx

You need to add -lm to the command line. That will tell gcc to link to
the math library.

Steve


On Mon, Aug 05, 2002 at 03:28:30PM -0500, bruce wrote:
> 
> I'm in chapter 2 of Kernighan and Richey, trying to learn c programming.
> I have been using gcc to compile my programs.  I wrote a very simple program 
> using math.hand sqrt:
> 
> #include <stdio.h>
> #include <math.h>
> main()                   {
> double m, n=8.0;
> m=sqrt(n);
> printf("%f\n",m);
> return 0;
> }
> 
> and tried to compile it with "gcc -o test-p45 test-p45.c"
> 
> It errored with 
>  undefined reference to `sqrt'
> 
> Same thing when I used kgcc and gcc3.
> I compiled it with g++ and it compiled and ran correctly.
> 
> Can anyone tell me why gcc seems to not be linking to math.h?
> Or should I be using g++ ? (I thought g++ was for C++ and gcc was for plain 
> old c.
> 
> I am using RH 7.2. and KDE.
> bruce
> -- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
> visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
-- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]