Stdio.h not found on Mac, how to add system headers includes into clang?

On Mac Os version 14.4
So when I run /Users/anon1238901/Documents/Compiler/backup4/llvm-project/build/bin/clang -S -emit-llvm test_header.c -o test_header.ll --target=$experiment
I get:

#include <stdio.h>
         ^~~~~~~~~
1 error generated.

test_header.c looks like

#include <stdio.h>

int main() {
        return 0;
}

I ran the same command with -v and noticed the include paths for the built compiler don’t have stdio.h, stdlib.h, etc.

...
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Users/anon1238901/Documents/Compiler/backup4/llvm-project/build/lib/clang/14.0.0/include

Running the same command with llvm’s clang with clang -S -emit-llvm test_header.c -o test_header.ll -v I don’t get that error. And my include paths now are (which do have stdio.h, stdlib.h…)

#include <...> search starts here:
 /usr/local/Cellar/llvm/17.0.6_1/lib/clang/17/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)

Also, when I remove --target=$experiment from my command I get the correct include paths, and don’t get that error.

 /Users/anon1238901/Documents/Compiler/backup4/llvm-project/build/lib/clang/14.0.0/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)

So how can I ensure that clang uses the right headers (system ones) even with the --target=$experiment?

I tried different fixes such as exporting CPLUS_INCLUDE_PATH path, using the -isysroot to point to mac’s sdk, or setting SDKROOT with macs sdk path. They don’t fix the issue and give several other errors when trying to read the include files like

error: Unsupported architecture
error: architecture not supported
error: unknown type name '__int64_t'; did you mean '__int128_t'?
...
error: unknown type name '__darwin_va_list'
fatal error: too many errors emitted

I recommend using:

-isysroot $(xcrun -show-sdk-path -sdk macosx)

assuming $experiment is a macos triple. You should adjust the sdk accordingly if for example you’re cross-compiling for iOS.