From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Berthelot To: nimrod99@dingoblue.net Cc: gcc-help@gcc.gnu.org Subject: Re: Problem with header files. Date: Fri, 03 Aug 2001 16:43:00 -0000 Message-id: <3B6B3680.C121BA1C@magma-da.com> References: <01080409411301.19611@Hand_Of_God> X-SW-Source: 2001-08/msg00043.html Ok I think it's quite easy: you forgot to specify the library for linking, you should do: gcc trial.c -lm libm is the math library, when referring to a library you put -l (instead of lib), so -lm link with the math library. David Matt R wrote: > Dear GCC Gurus, > I have a problem getting GCC to refer to header files. > For example the following program.... > ------------Code Begins Here------------ > #include > #include > > main() { > float uno; > float duo; > uno=7.778; > duo=sqrt(uno); > printf("sqrt of %f is %f \n", uno, duo); > } > > ------------Code Ends Here-------------- > Produces the following message at compile time... > > [fakeuser@fakehost BeginC]$ gcc trial.c > /tmp/ccBm2UFL.o: In function `main': > /tmp/ccBm2UFL.o(.text+0x1b): undefined reference to `sqrt' > collect2: ld returned 1 exit status */ > > __________________________________________ > > What is going on? I would really appreciate your advice on this > one. I have to admit to being a newbie to C programing. > I have installed glibc 2.2.12 (full install), and gcc 2.9.6-85, and > am using RedHat 7.0 distro. The original versions of glibc gave the > same errors. > > Looking forward to your advice...otherwise I will end up doin my > iminent assignments on DOS....a fate worse than death. > > Matt Redding