Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#66352 closed defect (worksforme)

clang-15: unable to locate default SDK

Reported by: judaew (Vadym-Valdis Yudaiev) Owned by:
Priority: Normal Milestone:
Component: ports Version: 2.8.0
Keywords: ventura, x86_64 Cc: cjones051073 (Chris Jones), judaew (Vadym-Valdis Yudaiev)
Port: clang-15

Description

The following error occurs when compiling any file:

$>>> cat test2.cpp
#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}

$>>> clang++-mp-15 -c test2.cpp 
In file included from test2.cpp:1:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/iostream:41:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/ios:220:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/__ios/fpos.h:14:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/iosfwd:99:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/__mbstate_t.h:29:
/opt/local/libexec/llvm-15/bin/../include/c++/v1/wchar.h:123:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

Change History (17)

comment:1 Changed 16 months ago by cjones051073 (Chris Jones)

Cannot reproduce (on macOS12)

Oberon ~/cernbox/MacPorts > cat test2.cpp 
#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}
Oberon ~/cernbox/MacPorts > clang++-mp-15 -c test2.cpp 
Oberon ~/cernbox/MacPorts > clang++-mp-15  test2.cpp  
Oberon ~/cernbox/MacPorts > ./a.out 
Hello World!%                                    

So either an issue with macOS13 (which I doubt) or something specific to your install.

Please double check you have the correct Xcode and CLT installed for macOS13.

comment:2 Changed 16 months ago by jmroot (Joshua Root)

Summary: lvvm-15: lfatal error: '*.h' file not foundclang-15: fatal error: '*.h' file not found

comment:3 Changed 16 months ago by kencu (Ken)

if it’s still failing for you, add some verbosity flags to see what’s up, might help, eg:

-v -Wl,-v

comment:4 Changed 16 months ago by cjones051073 (Chris Jones)

Port: clang-15 added; llvm-15 removed

comment:5 Changed 16 months ago by judaew (Vadym-Valdis Yudaiev)

I found this comment about this issue:

https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/issues/1055#issuecomment-581920327

After adding the CPLUS_INCLUDE_PATH environment variable, everything works correctly. Maybe you could add notes about CPLUS_INCLUDE_PATH var (in case someone else finds this problem).

comment:6 Changed 16 months ago by kencu (Ken)

I have compiled about a billion lines of code over the past many years and have never needed to add that…

seems it must be something else about your setup, but glad you’re in business now!

comment:7 Changed 16 months ago by judaew (Vadym-Valdis Yudaiev)

I was also surprised that it was so. On macOS 12, everything worked for me without these settings. I used the pre-compiled version LLVM/Clang from MacPorts there. After updating to macOS 13 and building LLVM/Clang, I got this issue.

comment:8 Changed 16 months ago by kencu (Ken)

pls try this, so we can see what happens:

clang++-mp-15 -v -c test2.cpp 

comment:9 Changed 16 months ago by judaew (Vadym-Valdis Yudaiev)

clang version 15.0.5
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-15/bin
 (in-process)
 "/opt/local/libexec/llvm-15/bin/clang" -cc1 -triple x86_64-apple-macosx13.0.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 -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 820.1 -v -fcoverage-compilation-dir=/Users/judaew -resource-dir /opt/local/libexec/llvm-15/lib/clang/15.0.5 -I/opt/local/include -I/Library/Java/JavaVirtualMachines/jdk17/Contents/Home/include -stdlib=libc++ -internal-isystem /opt/local/libexec/llvm-15/bin/../include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /opt/local/libexec/llvm-15/lib/clang/15.0.5/include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/Users/judaew -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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o test.o -x c++ test.cpp
clang -cc1 version 15.0.5 based upon LLVM 15.0.5 default target x86_64-apple-darwin22.1.0
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/include
 /Library/Java/JavaVirtualMachines/jdk17/Contents/Home/include
 /opt/local/libexec/llvm-15/bin/../include/c++/v1
 /usr/local/include
 /opt/local/libexec/llvm-15/lib/clang/15.0.5/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
In file included from test.cpp:1:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/iostream:41:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/ios:220:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/__ios/fpos.h:14:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/iosfwd:99:
In file included from /opt/local/libexec/llvm-15/bin/../include/c++/v1/__mbstate_t.h:29:
/opt/local/libexec/llvm-15/bin/../include/c++/v1/wchar.h:123:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

comment:10 Changed 16 months ago by kencu (Ken)

you're missing the isysroot, at least.

Have you installed either Xcode or the CLTs (or both, ideally)?

And then you have to open Xcode at least once, so it can install a bunch of stuff.

comment:11 Changed 16 months ago by kencu (Ken)

compare what happens when you just use clang++ -v -c test2.cpp.

comment:12 Changed 16 months ago by judaew (Vadym-Valdis Yudaiev)

On macOS 13 I have only CTL, but no Xcode. Is there any way to fix this problem without installing Xcode?

If I use Clang from CTL, then the building works correctly. Why doesn't Clang from MacPorts set -isysroot by default?

/usr/bin/clang++ -v test2.cpp
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx13.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test2.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-strict-return -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.0 -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 820.1 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/opt/local/include -I/Library/Java/JavaVirtualMachines/jdk17/Contents/Home/include -I/usr/local/include -cxx-isystem /opt/local/libexec/llvm-15/include/c++/v1/ -cxx-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/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 -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -Wno-cast-function-type -Wno-bitwise-instead-of-logical -fdeprecated-macro -fdebug-compilation-dir=/Users/judaew -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+messageToSelfInClassMethodIdReturnType -clang-vendor-feature=+disableInferNewAvailabilityFromInit -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/wf/1v73g2h55x32pt1n0njr27v00000gn/T/test2-f60f97.o -x c++ test2.cpp
clang -cc1 version 14.0.0 (clang-1400.0.29.202) default target x86_64-apple-darwin22.1.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
ignoring duplicate directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/include
 /Library/Java/JavaVirtualMachines/jdk17/Contents/Home/include
 /usr/local/include
 /opt/local/libexec/llvm-15/include/c++/v1
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version macos 13.0.0 13.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o a.out -L/usr/local/lib /var/folders/wf/1v73g2h55x32pt1n0njr27v00000gn/T/test2-f60f97.o -lc++ -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a
Last edited 16 months ago by judaew (Vadym-Valdis Yudaiev) (previous) (diff)

comment:13 Changed 16 months ago by kencu (Ken)

my build of macports-clang-15 finds the SDK, whether Xcode is installed or not:

 % clang++-mp-15  -c -v test2.cpp
clang version 15.0.5
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-15/bin
 (in-process)
 "/opt/local/libexec/llvm-15/bin/clang" -cc1 -triple x86_64-apple-macosx13.0.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 -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test2.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.0 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 820.1 -v -fcoverage-compilation-dir=/Users/cunningh/Desktop -resource-dir /opt/local/libexec/llvm-15/lib/clang/15.0.5 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /opt/local/libexec/llvm-15/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/local/libexec/llvm-15/lib/clang/15.0.5/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -fdeprecated-macro -fdebug-compilation-dir=/Users/cunningh/Desktop -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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o test2.o -x c++ test2.cpp
clang -cc1 version 15.0.5 based upon LLVM 15.0.5 default target x86_64-apple-darwin22.1.0
ignoring nonexistent directory "/usr/local/include"
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:
 /opt/local/libexec/llvm-15/bin/../include/c++/v1
 /opt/local/libexec/llvm-15/lib/clang/15.0.5/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
% sudo mv /Applications/Xcode.app /Applications/Xcode-hidden.app
 % clang++-mp-15  -c -v test2.cpp                                
clang version 15.0.5
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-15/bin
 (in-process)
 "/opt/local/libexec/llvm-15/bin/clang" -cc1 -triple x86_64-apple-macosx13.0.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 -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test2.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.0 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 820.1 -v -fcoverage-compilation-dir=/Users/cunningh/Desktop -resource-dir /opt/local/libexec/llvm-15/lib/clang/15.0.5 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /opt/local/libexec/llvm-15/bin/../include/c++/v1 -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/local/libexec/llvm-15/lib/clang/15.0.5/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -fdeprecated-macro -fdebug-compilation-dir=/Users/cunningh/Desktop -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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o test2.o -x c++ test2.cpp
clang -cc1 version 15.0.5 based upon LLVM 15.0.5 default target x86_64-apple-darwin22.1.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/libexec/llvm-15/bin/../include/c++/v1
 /opt/local/libexec/llvm-15/lib/clang/15.0.5/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)

I have no real idea how it has come to pass that your build does not find the SDK, to be honest. You might look through your initialization scripts and make 100% sure you are not overwriting any environment variables setting the SDK or any such thing. You can play around with xcrun and xcodebuild on your system and see if they can find the SDK that should be there.

In the end, you can uninstall your copy of clang-15 and rebuild it from source.

But -- whatever is going on -- it is on your system and not a general MacPorts issue...

comment:14 Changed 16 months ago by kencu (Ken)

Summary: clang-15: fatal error: '*.h' file not foundclang-15: unable to locate default SDK

comment:15 Changed 16 months ago by judaew (Vadym-Valdis Yudaiev)

Thank you for taking the time for me. After rebuilding this port with Xcode installed, the issue disappeared. Currently, Clang finds SDKs both with and without Xcode.

P.S. If anyone gets this issue, then the best workaround without Xcode is the SDKROOT variable. It should help Clang find a path to the SDK.

export SDKROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
# or
export SDKROOT=$(xcrun --show-sdk-path)

comment:16 Changed 16 months ago by judaew (Vadym-Valdis Yudaiev)

Resolution: worksforme
Status: newclosed

comment:17 in reply to:  15 Changed 16 months ago by kencu (Ken)

Replying to judaew:

Thank you for taking the time for me. After rebuilding this port with Xcode installed, the issue disappeared. Currently, Clang finds SDKs both with and without Xcode.

I am not sure that building with Xcode installed was the fix.

Perhaps just rebuilding was the fix.

P.S. If anyone gets this issue, then the best workaround without Xcode is the SDKROOT variable. It should help Clang find a path to the SDK.

This is a short-term fix that will not work out well in the long run I believe.

Note: See TracTickets for help on using tickets.