Advertisement
Shishire

Static linking issues

Oct 22nd, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. shishire@achilles:~$ cat sieve.c
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. char*
  6. eratosthenes(int n, int *c)
  7. {
  8. char* sieve;
  9. int i, j, m;
  10.  
  11. if(n < 2)
  12. return NULL;
  13.  
  14. *c = n-1; /* primes count */
  15. m = (int) sqrt((double) n);
  16.  
  17. /* calloc initializes to zero */
  18. sieve = calloc(n+1,sizeof(char));
  19. sieve[0] = 1;
  20. sieve[1] = 1;
  21. for(i = 2; i <= m; i++)
  22. if(!sieve[i])
  23. for (j = i*i; j <= n; j += i)
  24. if(!sieve[j]){
  25. sieve[j] = 1;
  26. --(*c);
  27. }
  28. return sieve;
  29. }
  30.  
  31. int main(int argc, char *argv)
  32. {
  33. int *array, n=0xFFFF;
  34. array =(int *)malloc(sizeof(int));
  35. eratosthenes(n,array);
  36. return 0;
  37. }
  38. shishire@achilles:~$ gcc -o sieve -static -static-libgcc -static-libstdc++ -lm sieve.c
  39. /tmp/ccgpiyqD.o: In function `eratosthenes':
  40. sieve.c:(.text+0x35): undefined reference to `sqrt'
  41. collect2: error: ld returned 1 exit status
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement