I checked out and built clang as per the docs Getting Started page[0].

When using clang, however, compilation of C and C++ projects fail to
find the needed headers from their respective standard libraries.

I can get around this in C projects by setting the environment variable
SDKROOT[1], and for C++ projects by setting the CPLUS_INCLUDE_PATH[2];
however, this feels a bit clunky so I thought this would be the best
place to ask if there’s a more appropriate way for macOS users to help
clang find what it needs when built from source. Maybe something needs
to be configured in clang/CMakeLists.txt, but I need to get the built
clang to search the same paths as the system clang, shown below after
the "… search starts here:" lines.

For reference:

macOS Catalina Version 10.15.7 (19H524)
Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; 
root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

-> Locally built clang
----8<----------------------------------------------------------------
$ ~/depot/llvm-project/build/bin/clang -std=c++17 -stdlib=libc++ -Wall -Werror 
-Iinclude -fsyntax-only src/word.cpp -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git 
92da5b711970610a2246cfa1baff5c2a63559e1b)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Users/mark/depot/llvm-project/build/bin
ignoring nonexistent directory 
"/Users/mark/depot/llvm-project/build/bin/../include/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
 (in-process)
 "/Users/mark/depot/llvm-project/build/bin/clang-13" -cc1 -triple 
x86_64-apple-macosx10.15.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix 
-Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -fsyntax-only 
-disable-free -main-file-name word.cpp -mrelocation-model pic -pic-level 2 
-mframe-pointer=all -fno-rounding-math -munwind-tables 
-fcompatibility-qualified-id-block-type-checking 
-fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu 
generic -debugger-tuning=lldb -target-linker-version 609.8 -v 
-fcoverage-compilation-dir=/Users/mark/Documents/projects/vault/cdict-dev 
-resource-dir /Users/mark/depot/llvm-project/build/lib/clang/13.0.0 -I include 
-stdlib=libc++ -internal-isystem /usr/local/include -internal-isystem 
/Users/mark/depot/llvm-project/build/lib/clang/13.0.0/include 
-internal-externc-isystem /usr/include -Wall -Werror -std=c++17 
-fdeprecated-macro 
-fdebug-compilation-dir=/Users/mark/Documents/projects/vault/cdict-dev 
-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 -x c++ src/word.cpp
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target 
x86_64-apple-darwin19.6.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 include
 /usr/local/include
 /Users/mark/depot/llvm-project/build/lib/clang/13.0.0/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
In file included from src/word.cpp:1:
include/word.h:1:10: fatal error: 'algorithm' file not found
#include <algorithm>
         ^~~~~~~~~~~
1 error generated.
---------------------------------------------------------------->8----

-> System clang
----8<----------------------------------------------------------------
$ clang -std=c++17 -stdlib=libc++ -Wall -Werror -Iinclude -fsyntax-only 
src/word.cpp -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ignoring nonexistent directory 
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
 
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
 -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage 
-Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration 
-fsyntax-only -disable-free -disable-llvm-verifier -discard-value-names 
-main-file-name word.cpp -mrelocation-model pic -pic-level 2 -mthread-model 
posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables 
-target-sdk-version=11.1 -target-cpu penryn -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/MacOSX.platform/Developer/SDKs/MacOSX.sdk
 -I include -I/usr/local/include -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/MacOSX.platform/Developer/SDKs/MacOSX.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/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 -internal-externc-isystem 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 -Wall -Werror -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 
-std=c++17 -fdeprecated-macro -fdebug-compilation-dir 
/Users/mark/Documents/projects/vault/cdict-dev -ferror-limit 19 
-fmessage-length 238 -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=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 
-fdiagnostics-show-option -fcolor-diagnostics -x c++ src/word.cpp
clang -cc1 version 12.0.0 (clang-1200.0.32.29) default target 
x86_64-apple-darwin19.6.0
ignoring nonexistent directory 
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory 
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 include
 /usr/local/include
 
/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/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
 (framework directory)
End of search list.
---------------------------------------------------------------->8----

n.b. Although the above demonstrates the failure of a C++ build, the
same failure (i.e., unable to find headers) occurs for C builds too.

Any pointers to solve this problem would be appreciated; or even an idea
of where to poke around if something needs to be patched because this
can’t yet be configured would also be good. Thanks.

[0]: https://clang.llvm.org/get_started.html
[1]: export SDKROOT="`xcrun --show-sdk-path`"
[2]: export 
CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1


--
Mark Jamsek <m...@bsdbox.org>

_______________________________________________
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users

Reply via email to