sqrt problem

Ali Abdul Ghani blade.vp2020@gmail.com
Mon Nov 17 18:16:00 GMT 2014


hi

I have a problem
I try compile This code in gnu/linux


#include <stdio.h>

char* eratosthenes (int n, int *c)
{
  char* sieve;
  int i, j, m;
if (n < 2) { *c = 0; return NULL; }
*c = n-1;     /* primes count */
  m = (int)
sqrt ((double) n);
/* calloc initializes to zero */
  sieve =
calloc
 (n+1, sizeof(char));
  sieve[0] = 1;
  sieve[1] = 1;
  for (i = 2; i <= m; i++) {
    if (sieve[i] == 0) {
      for (j = i*i; j <= n; j += i) {
        if (sieve[j] == 0) {
          sieve[j] = 1;
          --(*c);
        }
      }
    }
  }
  return sieve;
}

main()
{

}

in mngw its Work
but in gnu/linux gcc 4.8.2
gives me this Error
gcc q.c -o q
q.c: In function 'eratosthenes':
q.c:10:1: warning: incompatible implicit declaration of built-in
function 'sqrt' [enabled by default]
 sqrt ((double) n);
 ^
q.c:13:1: warning: incompatible implicit declaration of built-in
function 'calloc' [enabled by default]
 calloc
 ^
/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?



More information about the Gcc-help mailing list