可能重复:
c programming problem
我写了一个用于计算文件校验和的代码。但是当我编译它时,它向我展示了我无法解决的问题。我使用的是ubuntu 10.04作为我的操作系统。
我计算校验和的代码是这样的:
#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 ;
}
我使用名称checksum.c保存它并使用以下命令对其进行编译:
gcc checksum.c
我收到以下消息:
/tmp/ccatkZlp.o :( eh_frame + 0×12): 未定义的引用 `__gxx_personality_v0'collect2:ld 返回1退出状态
现在有人可以告诉我这个程序我做错了什么吗?这些错误是什么?为什么会这样?
请帮助我,我完全陷入困境。
答案 0 :(得分:1)
在文件顶部,#include <stdio.h>
之前,添加
#ifdef __cplusplus
#error Compile with a C compiler
#endif