在Apple M1上,我试图编译以下代码:
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
inline uint32_t rotl32(uint32_t x, int32_t bits)
{
return x<<bits | x>>(32-bits); // C idiom
}
uint32_t bad_hash32(char const *input) {
uint32_t result = 0xC0FF117;
while (*input) {
result ^= *input++;
result = rotl32(result, 5);
}
return result;
}
int main(int argc, char* argv[])
{
char const* const input = argv[1];
printf("%08xn", bad_hash32(input));
return 0;
}
命令:
gcc bad_hash.c -o bad_hash
产生以下错误:
Undefined symbols for architecture arm64:
"_rotl32", referenced from:
_bad_hash32 in bad_hash-4c8a24.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
有什么问题吗?我试图升级gcc到最新版本。
叮当声版本:
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
删除inline
说明符可修复此问题。
虽然我仍然不知道为什么会这样。