Why doesn't the following program compile with clang?
#include <stdio.h>
inline int f() {
return 42;
}
int main() {
printf("%d\n", f());
}
I get the following:
$ clang -o inline inline.c
Undefined symbols for architecture arm64:
"_f", referenced from:
_main in inline-975155.o
ld: symbol(s) not found for architecture arm64
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
But I can compile it with clang just fine. Is there some nuance between inline
in C vs C ?
CodePudding user response:
In C99 you need to provide an alternate (non-inline) definition of the function for when the compiler can't inline. See
https://godbolt.org/z/dh3G18PqK
CLANG works exactly the same way: