'clang: _rotl32 not found for architecture arm64
On Apple M1, I'm trying to compile the following code:
#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("%08x\n", bad_hash32(input));
return 0;
}
Command:
gcc bad_hash.c -o bad_hash
It produces the following error:
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)
What's the issue here? I tried to upgrade gcc to the latest.
Clang version:
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
Solution 1:[1]
Removing the inline specifier fixes the issue.
Though I still don't know why this happens.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andriy Makukha |
