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

[linux-help] 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] A c problem
From: bruce <bbales@xxxxxxx>
Date: Mon, 5 Aug 2002 15:28:30 -0500
Reply-to: linux-help@xxxxxxxxx

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


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