sqrt problem

Andrew Haley aph@redhat.com
Mon Nov 17 18:27:00 GMT 2014


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.



More information about the Gcc-help mailing list