Can't build clang and libc on macOS?

I’m trying to build the latest clang from git. I did…

> git pull
> mkdir build; cd build
> cmake -S ../llvm -DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libc" -DCMAKE_BUILD_TYPE=Release -G Ninja
> cmake --build .

I got this error below.

CMake Error at /Users/rob/Dev/llvm-project/libc/cmake/modules/LLVMLibCArchitectures.cmake:149 (message):
  Unsupported libc target operating system apple
Call Stack (most recent call first):
  /Users/rob/Dev/llvm-project/libc/CMakeLists.txt:62 (include)

I have an Intel MacBook running macOS 13.1.

Moments before I had successfully built it, using the same commands but without the “libc” in the list of runtimes. I tried adding the libc because I couldn’t compile a “helloworld”.

> ~/Dev/llvm-project/build/bin/clang main.c
main.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>

It’s supposed to be darwin not apple, so not sure why that’s gone wrong.

But building LLVM libc probably isn’t what you want. If you just want to compile code, you need to tell upstream Clang where the macOS SDK sysroot is (xcrun --show-sdk-path will show it) via -isysroot (or via the SDKROOT environment variable).

1 Like

The LLVM libc does not support Intel Macs. It only supports Apple Silicon.

On macOS, you need to specify -isysroot to tell clang where to look for the system headers. You can get the sys root path for macOS (e.g. xcode - How to get the path of latest SDK available on Mac - Stack Overflow)

You should be able to use clang without needing to build libc by doing something like:

clang -isysroot `xcrun -sdk macosx --show-sdk-path` main.c
1 Like