-1

Possible Duplicate:
c programming problem

I wrote a code for calculating the checksum of file. But when I compile it, it shows me problems which I'm unable to resolve.I'm using ubuntu 10.04 as my operating system.

My code for calculating the checksum is this:

#include <stdio.h>
#include <stdlib.h>

unsigned checksum(void *buffer, size_t len, unsigned int seed)
{
      unsigned char *buf = (unsigned char *)buffer;
      size_t i;

      for (i = 0; i < len; ++i)
            seed += (unsigned int)(*buf++);
      return seed;
}


int main()
{
      FILE *fp;
      size_t len;
      char buf[4096], file[] = "/home/manish.yadav/filename.c";

      if (NULL == (fp = fopen(file, "rb")))
      {
            printf("Unable to open %s for reading\n", file);
            return -1;
      }
      len = fread(buf, sizeof(char), sizeof(buf), fp);
      printf("%zd bytes read\n", len);
      printf("The checksum of %s is %u\n", file, checksum(buf, len, 0));

      return 0 ;
}

I saved it with name checksum.c and compiled it with the following command:

gcc checksum.c

I got the following message:

/tmp/ccatkZlp.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status

Now can anybody tell me what I'm doing wrong in this program ? what are these error and why they come ?

Please help me I'm completely stuck.

Community
  • 1
  • 1
user513164
  • 1,788
  • 3
  • 20
  • 26

1 Answers1

1

At the top of the file, right before the #include <stdio.h>, add

#ifdef __cplusplus
#error Compile with a C compiler
#endif
pmg
  • 106,608
  • 13
  • 126
  • 198