Stdio.h not found on Mac M1

I am trying to build llvm from source on mac. The build works fine unless I include some c library when compiling using the source built clang.

This is the command I am using:

$(CLANG) $(name).c -O0 -Xclang -disable-O0-optnone -S -emit-llvm -o $(name).ll


/Users/th3_st4rk/compiler/llvm-project/build/bin/clang test.c -O0 -Xclang -disable-O0-optnone -S -emit-llvm -o test.ll
test.c:1:10: fatal error: 'stdio.h' file not found
    1 | #include "stdio.h"
      |          ^~~~~~~~~
1 error generated.
make: *** [compile] Error 1

I am not sure if this is something related to Mac. However, I have checked the output with -print-resource-dir. The source built clang has stdio.h in resource_dir/include/llvm_libc_wrappers. While the system’s clang has no such directory.

On macOS, the standard library headers are part of the Xcode SDK. I assume you have either Xcode or the Command Line Tools installed. xcrun --show-sdk-path will show the appropriate SDK path, and you can add an -isysroot argument for it. You can also run your built Clang binary via xcrun instead of directly to add the SDK path automatically. I’m not sure if there’s a more convenient way to do this now.

1 Like


1 Like