[llvm-bugs] [Bug 45880] regression: locally-built Clang can't find C++ stdlib headers on Mac
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Sep 7 14:16:36 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=45880
Louis Dionne <ldionne at apple.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Fixed By Commit(s)| |a3a24316087d0e1b4db0b8fee19
| |cdee8b7968032
--- Comment #21 from Louis Dionne <ldionne at apple.com> ---
Sean, do you have an Apple SDK installed? If so, you need to point Clang to
those headers using one of the options below, otherwise Clang can't possibly
guess where to use those headers from. Apple made the decision not to ship
headers as part of the root system (which makes sense IMO since those are not
necessary to run any software, so there is no reason for non-developer users to
have those headers), and that means you need to tell Clang where to find them.
The only thing we could do here is somehow try to guess what SDK you want to
compile with, and set the `-isysroot` based on running `$(xcrun --sdk
<the-sdk-you-want-to-use> --show-sdk-path)` from the Clang driver. I'm not sure
that's a great solution, because how would we guess which SDK to use?
This issue was originally for C++, however that part of the issue was resolved.
By default the libc++ headers shipped in <install>/../include/c++/v1 will be
used, but you still need to use xcrun so it can find the C library headers:
$ echo "#include <iostream>" | xcrun /path/to/clang++ -fsyntax-only -xc++ -
The `xcrun` bit will tell Clang what's the path to the SDK, and Clang should
set up the correct header search paths based on that. Alternatively, you can
drop `xcrun` and use `-isysroot` instead:
$ echo "#include <iostream>" | /path/to/clang++ -fsyntax-only -xc++ -
-isysroot $(xcrun --show-sdk-path)
Another alternative, which might be what you're looking for since you seem to
want to use `clang` without any special flags, would be to globally set the
root of the SDK using:
$ export SDKROOT=$(xcrun --show-sdk-path)
$ echo "#include <iostream>" | /path/to/clang++ -fsyntax-only -xc++ -
However, in all cases, that has to be performed on the user side because we
can't know what the path of the SDK will be when we build Clang.
TL;DR: I suspect what you want is to add `export SDKROOT=$(xcrun
--show-sdk-path)` to your `.zshrc` and be done with it, however you'll have to
override `SDKROOT` if you ever want to compile with a LLVM Clang for a
different SDK. I'm going to close this as RESOLVED since the underlying issue
with C++ headers has been solved with a combination of
a3a24316087d0e1b4db0b8fee19cdee8b7968032 and Apple shipping libc++ headers in
recent SDKs.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210907/598ea144/attachment-0001.html>
More information about the llvm-bugs
mailing list