Open
Description
On most platforms, clang hello.c
works out of the box for builds targeting the host platform. However, as of LLVM/Clang 20.1.2, this is not the case on macOS:
$ cat main.c
int main(void) { return 0; }
$ clang main.c
ld: library 'System' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ cat hello.c
#include <stdio.h>
int main(void) { printf("Hello, world!"); return 0; }
$ clang hello.c
hello.c:1:10: fatal error: 'stdio.h' file not found
1 | #include <stdio.h>
| ^~~~~~~~~
1 error generated.
Instead one must manually populate the SDKROOT
environment variable (or pass -isysroot
):
$ export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
$ clang main.c
$ clang hello.c
It seems reasonable to expect clang
to select a default sysroot automatically on macOS even when SDKROOT
is not set in the environment.