Skip to content

[clang] Driver does not select a default -isysroot when targeting macOS #137352

Open
@bradking

Description

@bradking

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'platform:macos

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions