This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: sqrt problem
- From: Andrew Haley <aph at redhat dot com>
- To: Ali Abdul Ghani <blade dot vp2020 at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 17 Nov 2014 18:27:24 +0000
- Subject: Re: sqrt problem
- Authentication-results: sourceware.org; auth=none
- References: <CAHWa5ueTpz+VSgt7iLyALetF1+cZV2sVZwvSWnkqwO_OaBR=xQ at mail dot gmail dot com>
On 11/17/2014 06:16 PM, Ali Abdul Ghani wrote:
> /tmp/cc0fh9Tm.o: In function `eratosthenes':
> q.c:(.text+0x31): undefined reference to `sqrt'
> collect2: error: ld returned 1 exit status
> What is the problem and what is the solution?
If you want math, you link with libm.
http://stackoverflow.com/questions/5419366/why-do-i-have-to-explicitly-link-with-libm
http://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c
This has been so since the dawn of time itself.
Andrew.