build svn clang with stdlibc++ 4.7 - c++

I am new to compile clang directly from svn. I want to build clang against stdlibc++4.7.
My system is running Mac OS mountain lion 10.8, so I used MacPorts to install gcc47. Now the library is in /opt/local/lib/gcc47 and headers are in /opt/local/include/gcc47.
I downloaded clang from svn and followed the guide from: http://clang.llvm.org/get_started.html
how do i specify clang configure to use stdlibc++ 4.7? It mentions in the guide that i should specify it using --with-gcc-toolchain. What exactly should I use with --with-gcc-toolchain? is it just ../configure --with-gcc-toolchain
I also tried to compile gcc from svn and install it into my home directory as $HOME/gcc. And then pass configure with --with-gcc-toolchain=PATH_TO_GCC_IN_HOME_DIR. After compilation, and tried the following:
./clang -v -x c++ /dev/null -fsyntax-only
it still shows linked with gcc4.2 lib that came with Mac OS:
clang version 3.2 (trunk 161295)
Target: x86_64-apple-darwin12.0.0
Thread model: posix
"/Users/chen/Repository/build/Debug+Asserts/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -fsyntax-only -disable-free -main-file-name null -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -v -resource-dir /Users/chen/Repository/build/Debug+Asserts/bin/../lib/clang/3.2 -fmodule-cache-path /var/folders/1l/m5km38_d3lxbrvysgv6s42680000gn/T/clang-module-cache -fdeprecated-macro -fdebug-compilation-dir /Users/chen/Repository/build/Debug+Asserts/bin -ferror-limit 19 -fmessage-length 145 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -x c++ /dev/null
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-apple-darwin12.0.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/Users/chen/Repository/build/Debug+Asserts/bin/../lib/clang/3.2/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
How can I compile clang with libstdc++ 4.7?
Thanks,

Related

clangd-14 cannot find c++ headers

How can I make clangd find c++ libs?
Here is a simple example, given this cpp main file
// main.cpp
#include <string>
int main() {
return 0;
}
I am generating the compile_commands.json db using bear:
$ bear -- g++ main.cpp
This gives the following compile_commands.json:
[
{
"arguments": [
"/usr/bin/g++",
"-c",
"main.cpp"
],
"directory": "/tmp/test",
"file": "/tmp/test/main.cpp"
}
]
If I want to check if clangd-14 would work on this small project, it can't find <string>
$ clangd --check=main.cpp
I[00:26:23.073] Ubuntu clangd version 14.0.0-1ubuntu1
I[00:26:23.073] Features: linux+grpc
I[00:26:23.073] PID: 32847
I[00:26:23.073] Working directory: /tmp/test
I[00:26:23.073] argv[0]: clangd
I[00:26:23.073] argv[1]: --check=main.cpp
I[00:26:23.073] Entering check mode (no LSP server)
I[00:26:23.073] Testing on source file /tmp/test/main.cpp
I[00:26:23.073] Loading compilation database...
I[00:26:23.073] Loaded compilation database from /tmp/test/compile_commands.json
I[00:26:23.074] Compile command from CDB is: /usr/bin/g++ --driver-mode=g++ -c -resource-dir=/usr/lib/llvm-14/lib/clang/14.0.0 -- /tmp/test/main.cpp
I[00:26:23.074] Parsing command...
I[00:26:23.076] internal (cc1) args are: -cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/test -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/tmp/test -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /tmp/test/main.cpp
I[00:26:23.076] Building preamble...
I[00:26:23.088] Indexing headers...
E[00:26:23.089] [pp_file_not_found] Line 1: 'string' file not found
I[00:26:23.089] Building AST...
I[00:26:23.096] Indexing AST...
I[00:26:23.096] Testing features at each token (may be slow in large files)
I[00:26:23.097] All checks completed, 1 errors
How can I make clangd to work with c++ headers?
$ clangd --version
Ubuntu clangd version 14.0.0-1ubuntu1
Features: linux+grpc
Platform: x86_64-pc-linux-gnu
If you're on Ubuntu 22.04, this is a common issue.
The easiest workaround is to install the package libstdc++-12-dev, as discussed in this answer.
Additional discussion, including other possible workarounds, and discussion of what a proper fix might look like on the clangd side, can be found in this clangd issue (see in particular this comment).

Qt Quick app (or other) deploy on iOS device or emulator

I has Mac OS big sur 11.1, Xcode 12.3(12c33), qt 5.14.2 + qt creator 4.11.1 ( installed with online installer). I made simple project qt quick, build for macos working well, but when i try to build it for iOS emulator, I getting this error:
17:06:29: Running steps for project untitled...
17:06:29: Starting: "/Users/range/Qt5.14.2/5.14.2/ios/bin/qmake" /Users/range/untitled/untitled.pro -spec macx-ios-clang CONFIG+=iphonesimulator CONFIG+=simulator CONFIG+=qml_debug -after
Project ERROR: Cannot run target compiler '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++'. Output:
===================
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include/c++/v1"
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-ios14.3.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=14.3 -target-cpu core2 -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -fdeprecated-macro -fdebug-compilation-dir /Users/range/Qt5.14.2/5.14.2/ios/mkspecs/features -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=ios-14.3.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -o /var/folders/j0/wkdnpcrd32x6lfr0z6rz29c40000gn/T/--aab3ee.o -x c++ -
clang -cc1 version 12.0.0 (clang-1200.0.32.28) default target x86_64-apple-darwin20.2.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.x
ctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -dylib -arch x86_64 -platform_version ios 14.3.0 14.3 -single_module -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk -o /dev/null -v /var/folders/j0/wkdnpcrd32x6lfr0z6rz29c40000gn/T/--aab3ee.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.ios.a
#(#)PROGRAM:ld PROJECT:ld64-609.8
BUILD 20:09:52 Nov 4 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib/libc++.tbd, missing required architecture x86_64 in file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/usr/lib/libc++.tbd (4 slices)
ld: building for iOS, but linking in object file built for iOS Simulator, file '/var/folders/j0/wkdnpcrd32x6lfr0z6rz29c40000gn/T/--aab3ee.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
===================
Maybe you forgot to setup the environment?
17:06:30: The process "/Users/range/Qt5.14.2/5.14.2/ios/bin/qmake" exited with code 3.
Error while building/deploying project untitled (kit: Эмулятор Qt 5.14.2 for iOS)
When executing step "qmake"
17:06:30: Elapsed time: 00:01.
Accordingly I can’t generate project for xcode and build app for real device, since the same error occurs.
My sets:
Profiles:
Compilers:
What can be wrong?
I found a solution. You need to find all files called as "toolchain.prf" in qt instalation directory and change this code:
defineTest(qtCompilerError) {
!cross_compile: \
what =
else: host_build: \
what = " host"
else: \
what = " target"
qtToolchainError("Cannot run$$what compiler '$$1'. Output:", $$2, \
"Maybe you forgot to setup the environment?")
}
to this code:
defineTest(qtCompilerError) {
# empty
}
After this everything works fine on ios and ios-emulator.

Clang on MacOS having problems with its includes

I have built from scratch Clang on MacOS and I am having problems with it.
Used following to configure Clang for building:
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/clang-12 -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;lldb" ../llvm
This is my test program:
#include <ostream>
#include <algorithm>
int main(int argc, char** argv) {
return 0;
}
OK if compiled with Clang 11.0.3 that ships with XCode clang++ -c test.cc
ERROR if using new Clang 12 (built) /opt/clang-12/bin/clang++ -c test.cc
In file included from test.cc:2:
In file included from /opt/clang-12/bin/../include/c++/v1/ostream:138:
In file included from /opt/clang-12/bin/../include/c++/v1/ios:214:
In file included from /opt/clang-12/bin/../include/c++/v1/iosfwd:95:
/opt/clang-12/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
Depending on what I am trying to include I get different include errors.
➜ tests /opt/clang-12/bin/clang++ -v -c test.cc
clang version 12.0.0 (https://github.com/llvm/llvm-project.git b529c5270c99e0ca18e3cbd9a5f50eb0970e560a)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /opt/clang-12/bin
(in-process)
"/opt/clang-12/bin/clang-12" -cc1 -triple x86_64-apple-macosx10.15.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cc -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir /opt/clang-12/lib/clang/12.0.0 -stdlib=libc++ -internal-isystem /opt/clang-12/bin/../include/c++/v1 -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /opt/clang-12/lib/clang/12.0.0/include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /Users/duddie/Projects/Audio/1voct/1voct_modular/tests -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -o test.o -x c++ test.cc
clang -cc1 version 12.0.0 based upon LLVM 12.0.0git default target x86_64-apple-darwin19.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/clang-12/bin/../include/c++/v1
/usr/local/include
/opt/clang-12/lib/clang/12.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
In file included from test.cc:2:
In file included from /opt/clang-12/bin/../include/c++/v1/ostream:138:
In file included from /opt/clang-12/bin/../include/c++/v1/ios:214:
In file included from /opt/clang-12/bin/../include/c++/v1/iosfwd:95:
/opt/clang-12/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
ERROR if Clang 11.0.3 (XCode) or Clang 12 but target for ARM clang++ -target arm-none-eabi -c test.cc
test.cc:2:10: fatal error: 'ostream' file not found
#include <ostream>
^~~~~~~~~
1 error generated.
Any ideas what am I doing wrong?
Add the following to the shell profile file ~/.bash_profile or ~/.zsh_profile or any other way to set environment variable accessible to the shell you're running it in.
export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"
Verify the correct path to the SDK on your macOS/Xcode version.
Reopen Terminal (sourcing the file may not work reliably).
Then try your compile command again.
/opt/clang-12/bin/clang++ -c test.cc
The Command Line Tools package installs the macOS system headers
inside the macOS SDK. Software that compiles with the installed tools
will search for headers within the macOS SDK provided by either Xcode
at:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
or the Command Line Tools at:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk depending on which
is selected using xcode-select. The command line tools will search the
SDK for system headers by default. However, some software may fail to
build correctly against the SDK and require macOS headers to be
installed in the base system under /usr/include. If you are the
maintainer of such software, we encourage you to update your project
to work with the SDK or file a bug report for issues that are
preventing you from doing so. As a workaround, an extra package is
provided which will install the headers to the base system. In a
future release, this package will no longer be provided. You can find
this package at:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
https://developer.apple.com/documentation/xcode-release-notes/xcode-10-release-notes
Probably a more portable one (I found the hint at llvm-project/llvm/utils/lit/lit/util.py:399):
export SDKROOT=$(xcrun --show-sdk-path --sdk macosx)
Also, you can also add -isysroot argument to clang driver to alter the default system root for header searching:
clang++ a.cpp -isysroot $(xcrun --show-sdk-path --sdk macosx)
More details and investigation notes here
For what it's worth, I was able to fix the problem with MacOs Big Sur by doing
export SDKROOT='/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk'

Compile LLVM from sources on macOS Catalina (How to solve "stdio.h" not found)

I'm bringing to your attention a question I tackled with for a few days and no issue could solve for me, in the hope that it'll save some other people time.
I try to compile LLVM from sources on macOS Catalina (10.15).
To do so, I used the following commands (after following the LLVM build manual):
git clone https://github.com/llvm/llvm-project
cd llvm-project
mkdir build && cd build
cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE="Debug" ../llvm
ninja
Now you should have a working clang compiler under build/bin.
However, given /tmp/program.c with this contents:
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
I got the following output:
/tmp/program.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
I tried a lot of solutions, including setting CPATH, CFLAGS, CXXFLAGS, LDFLAGS etc but none worked.
System headers new path
Since macOS Catalina, the /usr folder is been mounted as a read-only directory, so even as a root - no one has permission to modify this folder (well, unless you reboot in SIP mode, which's obviously not a considerable solution).
The entire toolchain is saved by default under /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk. You can get your path by executing xcrun --show-sdk-path. I'll assume that you do have the default path in my answer but please adjust as needed.
Gathering information
Running clang with the -v flag gave me the following:
./clang /tmp/program.c -v --
clang version 11.0.0 (https://github.com/llvm/llvm-project 01641197ee0bd3895c756c925723c8c8e03bcb09)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: ~/llvm/llvm-project/build/bin/.
"~/llvm/llvm-project/build/bin/clang-11" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -main-file-name program.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir ~/llvm/llvm-project/build/lib/clang/11.0.0 -internal-isystem /usr/local/include -internal-isystem ~/llvm/llvm-project/build/lib/clang/11.0.0/include -internal-externc-isystem /usr/include -fdebug-compilation-dir ~/llvm/llvm-project/build/bin -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -o /var/folders/64/6bf82c_52ws1n4cwc376znvr0000gn/T/program-d111a4.o -x c /tmp/program.c
clang -cc1 version 11.0.0 based upon LLVM 11.0.0git default target x86_64-apple-darwin19.5.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
~/llvm/llvm-project/build/lib/clang/11.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
/tmp/program.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
Which can teach us that our include paths for system headers are:
/usr/local/include
~/llvm/llvm-project/build/lib/clang/11.0.0/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
Hence, we can see that the location of the new headers (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk) doesn't appear here and thus the error.
We could do a symbolic link from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk to /usr/local/include, but that'd create conflicting headers and have bad side effects (yes, I tried. Yes, it was very stupid...).
Solution
We can see that one of the default search headers path appears under the build directory (~/llvm/llvm-project/build/lib/clang/11.0.0/include). Symbolic-linking the standard headers to this directory won't create any dangerous conflicts.
Hence, all you need to do to solve this issue, is:
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/* ~/llvm/llvm-project/build/lib/clang/11.0
I hope that my answer will help others who struggle with this issue.
To be able to use clang compiled from LLVM sources on macOS, you can do the following:
Set PATH to include the bin directory where the newly built clang is located.
New clang needs to know where XCode SDK is located. You can do this by setting SDKROOT environment variable. For example:
SDKROOT=`xcrun --show-sdk-path` clang test.c
That should be it.

Boost no longer works with Homebrew on Mac El Capitan

I just updated from Yosemite to El Capitan and it has broken one of my C++ programs which was relying on Boost. Whenever I try to compile, I get these errors:
fatal error: 'boost/timer/timer.hpp' file not found
#include <boost/timer/timer.hpp>
fatal error: 'boost/program_options.hpp' file not found
#include "boost/program_options.hpp"
I've been compiling it with the correct flags and it worked perfectly before:
-lboost_timer-mt \
-lboost_program_options-mt \
I've followed the home-brew instructions to chown /usr/local, run brew doctor and brew update, even brew reinstall boost. I've also checked and timer.hpp is present in /usr/local/include/boost.
Update Ran: clang++ -E -x c++ - -v < /dev/null
Apple LLVM version 7.0.0 (clang-700.0.72) Target: x86_64-apple-darwin15.0.0 Thread model: posix "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
-cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.2 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
-stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /usr/local/lib -ferror-limit 19 -fmessage-length 272 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0
-fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ - clang -cc1 version 7.0.0 based upon LLVM 3.7.0svn default target x86_64-apple-darwin15.0.0 ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/v1" ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/local/include" ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.0/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks (framework directory) End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 332 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
You should install the Xcode Command Line tools with xcode-select --install to get a version of clang that searches /usr/local by default. Otherwise, you're using the versions provided by Xcode proper, which only search the OS X SDK paths. (/usr/bin/gcc and /usr/bin/g++ both invoke clang and are not actually versions of gcc.)
I had the same problem when I upgraded to El Capitan. I solved this problem reinstalling Boost with brew.
If you don't have brew installed, you can install it with
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then, install boost
brew install boost