我在程序中使用了crc。在ViewController.mm
ViewDidLoad
方法代碼如下:xcode c代碼編譯錯誤
char *testChars = "test chars";
crc32(0, (unsigned char*)testChars, strlen(testChars));
crc32
功能代碼如下:
uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len)
{
unsigned char *end;
crc = ~crc;
for (end = buf + len; buf < end; ++buf)
crc = crc32_table[(crc^*buf) & 0xff]^(crc >> 8);
return ~crc;
}
編譯錯誤是:
Undefined symbols for architecture x86_64,"crc32(unsigned int, unsigned char*, unsigned long)", referenced from:-[ViewController viewDidLoad:] in ViewController.o
。
我將ViewController.mm
更改爲ViewController.m
後,編譯成功。爲什麼?
您的標題不匹配的標籤。 C還是C++? – user2079303