[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [*] about gcc



On Mon, Feb 07, 2000 at 12:49:37AM +0800, =?ISO-8859-1?Q?=D5=C5=CF=FE=C0=DA@murphy.debian.org wrote:
> hello everybody:
> 
> i am using debian 2.1r4, i install it use deselect's preselect "scientific 
> workstation". i found my gcc doesn't allow me to use "sqrt", for example:
> 
> this is a c file: a.c
> 
> #include "stdio.h"
> #include "math.h"
> main(){
> printf("%f\n",sqrt(2));
> }
> 
> and execute "cc a.c"
> 
> i get:
> /tmp/ccc00242: In function 'main':
> /tmp/ccc00242(.text+0xb): undefined reference to 'sqrt'
> 
> so i had to use g++ instead, and it worked!
> 
> i had use this gcc to campile some math software such as "pari", "simath","rlab"...and 
> it work very well, not any error reported.
> 
> what is the problem? 

You incuded the headers wrong.  Try doing it like this:
#include <stdio.h>
#include <math.h>

If you put the name of the header in quotes that tells the compiler
to look first in the current directory, and then looks elsewhere with
the elsewhere being system dependant.  Putting the name of the header
in the angle brackets says that the headers are part of the standard
libraries.  Also you must give a compile time command to link in the
math library - add '-lm' to the end of the compile command.

Script started on Sun Feb  6 13:01:11 2000
HAL9000:~$ cat ./test1.c
#include <stdio.h>
#include <math.h>
main(){
printf("%f\n",sqrt(2));
}
HAL9000:~$ gcc -o test1 test1.c -lm
HAL9000:~$ ./test1
1.414214
HAL9000:~$ exit
Script done on Sun Feb  6 13:01:34 2000
-- 
Mike Werner  KA8YSD           |  "Where do you want to go today?"
ICQ# 12934898                 |  "As far from Redmond as possible!"
'91 GS500E                    |
Morgantown WV                 |  Only dead fish go with the flow.


Reply to: