0

I have used crc in my program.ViewDidLoad method code in ViewController.mm is below:

char *testChars = "test chars";
crc32(0, (unsigned char*)testChars, strlen(testChars));

crc32 function code is below:

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;

}

compile error is :

Undefined symbols for architecture x86_64,"crc32(unsigned int, unsigned char*, unsigned long)", referenced from:-[ViewController viewDidLoad:] in ViewController.o.

After I changed ViewController.mm to ViewController.m, compiled successfully. Why?

1
  • 2
    Your title does not match the tags. C or c++? Commented Nov 7, 2015 at 15:16

1 Answer 1

1

Your defining of crc is probably in a C file, not a C++ file, so the name isn't being mangled to a type specific version.

Your usage in a .mm file will be as if for C++, and hence will be name mangled.

By changing the containing file to .m, you compile it against C and hence the issue goes away.

Alternatively, you could change the crc file to have a C++ extension (c++ or cc)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.