Thread: What does the mean of error messages?

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    77

    What does the mean of error messages?

    Code:
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void SpecialNumber(int n)
    {
    	FILE *fw;
    	int i, j, k, d;
    	int *a;
    	d = 0;
    	a = malloc(n*sizeof(*a));
    	fw = fopen("SpecialNumber.out", "wt");
    	for (i = 2; i < pow(10, n); i++) {
    		for (j = 0, k = pow(10, n); k >= 10; j++) {
    			a[k] = (int)(i%j)/(j/10);
    			j/=10;
    		}
    		for (j = 0; j < n; j++) {
    			d += pow(a[j], n);
    		}
    		if (d == i)
    			fprintf(fw, "%5d", i);
    	}
    	free(a);
    	fclose(fw);
    }
    
    int main()
    {
    	FILE *fr;
    	int n;
    	fr = fopen("SpecialNumber.dat", "rt");
    	fscanf(fr, "%d", &n);
    	SpecialNumber(n);
    	fclose(fr);
    	return 0;
    }
    Code:
    mathsniper:~# gcc -O2 -o SpecialNumber SpecialNumber.c
    /tmp/cc4zGvKf.o: In function `SpecialNumber':
    SpecialNumber.c:(.text+0x56): undefined reference to `pow'
    SpecialNumber.c:(.text+0x79): undefined reference to `pow'
    SpecialNumber.c:(.text+0xe5): undefined reference to `pow'
    collect2: ld returned 1 exit status
    I have included the math.h but it show the error messages.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You also need to link with the math library
    Code:
    gcc prog.c -lm
    That's "minus L M" (but in lower case).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed