libstdc++ 10.3 doesn't provide <compare> - c++

So I just upgraded to clang 12 because I need <compare>, and as soon as I try to recompile I'm hit with
./test/math/ordering.cpp:6:10: fatal error: 'compare' file not found
#include <compare>
^~~~~~~~~
1 error generated.
I checked and (according to cppreference and the official gnu site) my version of libstdc++6, 10.3, is supposed to include this header. I'm compiling with this command:
clang++-12 ./test/math/ordering.cpp -o ./test/math/ordering.exe -I ./inc/lcu --include testing/assert.h -std=c++20 -stdlib=libstdc++
Running it with -v prints:
Ubuntu clang version 12.0.1-++20210825102835+fed41342a82f-1~exp1~20210825083541.133
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;#m64
Candidate multilib: 32;#m32
Candidate multilib: x32;#mx32
Selected multilib: .;#m64
"/usr/lib/llvm-12/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ordering.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-12/lib/clang/12.0.1 --include testing/assert.h -I ./inc/lcu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-12/lib/clang/12.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir /home/lenerdv/projects/games/lib/lcu -ferror-limit 3 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o /tmp/ordering-c353eb.o -x c++ ./test/math/ordering.cpp
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9"
#include "..." search starts here:
#include <...> search starts here:
./inc/lcu
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward
/usr/local/include
/usr/lib/llvm-12/lib/clang/12.0.1/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
./test/math/ordering.cpp:6:10: fatal error: 'compare' file not found
#include <compare>
^~~~~~~~~
1 error generated.
I ran apt update and apt upgrade, but everything was already up to date. Any ideas?

Related

Using clang-11 to cross compile for aarch64-linux-gnu on x86-64 error: 'bits/c++config.h' file not found

I am trying to use clang-11 to cross compile a c++ file to aarch-linux-gnu, from my host machine which is x86-64.
Here's the command :
clang-11 -v -target aarch64-linux-gnu -B/usr/aarch64-linux-gnu/lib -march=armv8.5-a+memtag -fsanitize=memtag test_mte.cpp -static
But, I run into this error:
In file included from /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/stdlib.h:36: /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/cstdlib:41:10: fatal error: 'bits/c++config.h' file not found #include <bits/c++config.h>
I have installed the packages gcc-multilib g++-multilib binutils-aarch64-linux-gnu libc6-arm64-cross libc6-dev-arm64-cross crossbuild-essential-arm64 gcc-aarch64-linux-gnu
How can I resolve this error?
Full Output:
Here's the full output of the clang-11 command:
`Debian clang version 11.0.1-2~bpo10+1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/lib/llvm-11/bin/clang" -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test_mte.cpp -static-define -mrelocation-model static -mframe-pointer=non-leaf -fmath-errno -fno-rounding-math -mconstructor-aliases -target-cpu generic -target-feature +neon -target-feature +v8.5a -target-feature +mte -target-abi aapcs -fallow-half-argum
ents-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-11/lib/clang/11.0.1 -internal-isystem /usr/bi
n/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../..
/include/aarch64-linux-gnu/c++/8 -internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/aarch64-linux-gnu/c++/8
-internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/local/include -in
ternal-isystem /usr/lib/llvm-11/lib/clang/11.0.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdepreca
ted-macro -fdebug-compilation-dir /home/aditi712/mte_Stuff -ferror-limit 19 -fsanitize=memtag -fno-signed-char -fgnuc-version=4.2.1 -fcxx-ex
ceptions -fexceptions -fcolor-diagnostics -faddrsig -o /tmp/test_mte-836487.o -x c++ test_mte.cpp
clang -cc1 version 11.0.1 based upon LLVM 11.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/aarch64-linux-gnu/c++/8"
ignoring nonexistent directory "/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/aarch64-linux-gnu/c++/8"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8
/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/backward
/usr/local/include
/usr/lib/llvm-11/lib/clang/11.0.1/include
/usr/include
End of search list.
In file included from test_mte.cpp:7:
In file included from /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/stdlib.h:36:
/usr/bin/../lib/gcc-cross/aarch64-linux-gnu/8/../../../../include/c++/8/cstdlib:41:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>`
It seems to me that clang is asking some gcc about system include paths, and this process fails (for some reason), leading to inclusion of host headers.
Here is a solution that helped me:
https://askubuntu.com/questions/947954/wrong-default-include-directories-for-clang-cross-compile
Basically you provide all system includes on your own. In our case (arm64), for me this boiled down to these flags:
-nostdinc++
-cxx-isystem /usr/aarch64-linux-gnu/include/c++/10/`
-cxx-isystem /usr/aarch64-linux-gnu/include/c++/10/aarch64-linux-gnu/
-isystem /usr/aarch64-linux-gnu/include

CLion does not properly detect clang as CUDA compiler

I use CMake 3.18 with CLion 2020.2.5 and want to use Clang as CUDA compiler. I do with this with the following two lines at the top of my CMakeLists.txt:
set(CMAKE_CUDA_COMPILER_ID Clang)
set(CMAKE_CUDA_COMPILER ${CMAKE_CXX_COMPILER})
And it works very well for the code, and I also CLion seems to be able to work with the code just fine. But it still complains while configuring the project:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mu/project
Problems were encountered while collecting compiler information:
Unexpected compiler output. This compiler might be unsupported.
If you are using GCC/Clang, please report the bug in https://youtrack.jetbrains.com/issues/CPP.
In the error log I find this:
Checking whether the CUDA compiler is NVIDIA using "" did not match "nvcc: NVIDIA \(R\) Cuda compiler driver":
clang version 11.0.0 (Fedora 11.0.0-2.fc33)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
In the output log it seems that it can identify the compiler just fine:
Checking whether the CUDA compiler is Clang using "" matched "(clang version)":
clang version 11.0.0 (Fedora 11.0.0-2.fc33)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" succeeded.
Compiler: /usr/bin/clang++
Build flags:
Id flags: --cuda-path=/usr/local/cuda;--cuda-gpu-arch=sm_52 -v
The output was:
0
clang version 11.0.0 (Fedora 11.0.0-2.fc33)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/10
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/10
Candidate multilib: .;#m64
Candidate multilib: 32;#m32
Selected multilib: .;#m64
Found CUDA installation: /usr/local/cuda, version 10.0
"/usr/bin/clang-11" -cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CMakeCUDACompilerId.cu -mrelocation-model static -mframe-pointer=all -fno-rounding-math -fno-verbose-asm -no-integrated-as -munwind-tables -aux-target-cpu x86-64 -fcuda-is-device -mlink-builtin-bitcode /usr/local/cuda/nvvm/libdevice/libdevice.10.bc -target-feature +ptx63 -target-sdk-version=10.0 -target-cpu sm_52 -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/11.0.0 -internal-isystem /usr/lib64/clang/11.0.0/include/cuda_wrappers -internal-isystem /usr/local/cuda/include -include __clang_cuda_runtime_wrapper.h -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fno-dwarf-directory-asm -fno-autolink -fdebug-compilation-dir /home/mu/project/CMakeFiles/3.18.4/CompilerIdCUDA -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -o /tmp/CMakeCUDACompilerId-b39068.s -x cuda CMakeCUDACompilerId.cu
clang -cc1 version 11.0.0 based upon LLVM 11.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10"
ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux"
ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward"
ignoring duplicate directory "/usr/local/include"
ignoring duplicate directory "/usr/lib64/clang/11.0.0/include"
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib64/clang/11.0.0/include/cuda_wrappers
/usr/local/cuda/include
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward
/usr/local/include
/usr/lib64/clang/11.0.0/include
/usr/include
End of search list.
"/usr/local/cuda/bin/ptxas" -m64 -O0 -v --gpu-name sm_52 --output-file /tmp/CMakeCUDACompilerId-0e6743.o /tmp/CMakeCUDACompilerId-b39068.s
ptxas info : 0 bytes gmem
"/usr/local/cuda/bin/fatbinary" --cuda -64 --create /tmp/CMakeCUDACompilerId-346390.fatbin --image=profile=sm_52,file=/tmp/CMakeCUDACompilerId-0e6743.o --image=profile=compute_52,file=/tmp/CMakeCUDACompilerId-b39068.s
"/usr/bin/clang-11" -cc1 -triple x86_64-unknown-linux-gnu -target-sdk-version=10.0 -aux-triple nvptx64-nvidia-cuda -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CMakeCUDACompilerId.cu -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/11.0.0 -internal-isystem /usr/lib64/clang/11.0.0/include/cuda_wrappers -internal-isystem /usr/local/cuda/include -include __clang_cuda_runtime_wrapper.h -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/mu/project/CMakeFiles/3.18.4/CompilerIdCUDA -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcuda-include-gpubinary /tmp/CMakeCUDACompilerId-346390.fatbin -faddrsig -o /tmp/CMakeCUDACompilerId-4af90f.o -x cuda CMakeCUDACompilerId.cu
clang -cc1 version 11.0.0 based upon LLVM 11.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10"
ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux"
ignoring duplicate directory "/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward"
ignoring duplicate directory "/usr/local/include"
ignoring duplicate directory "/usr/lib64/clang/11.0.0/include"
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib64/clang/11.0.0/include/cuda_wrappers
/usr/local/cuda/include
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux
/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward
/usr/local/include
/usr/lib64/clang/11.0.0/include
/usr/include
End of search list.
"/usr/bin/ld" --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-redhat-linux/10/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/10/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/10/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/10 -L/usr/lib/gcc/x86_64-redhat-linux/10/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/10/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/CMakeCUDACompilerId-4af90f.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/10/crtend.o /usr/lib/gcc/x86_64-redhat-linux/10/../../../../lib64/crtn.o
Compilation of the CUDA compiler identification source "CMakeCUDACompilerId.cu" produced "a.out"
The CUDA compiler identification is Clang, found in "/home/mu/project/CMakeFiles/3.18.4/CompilerIdCUDA/a.out"
How can I resolve with issue between CMake and CLion?

Clang without GCC or MSVC

I'd like to use clang without GCC on Linux and without MSVC on Windows. My understanding is that this wasn't possible in the past due to:
A LLVM linker wasn't available.
A compatible STL wasn't available.
However, my impression what that this should be possible with v8.0.0 as there is now a viable linker and a compatible STL library.
Unfortunately, I get different errors on Linux and Windows when exercising this scenario (see more info below).
Can you help me out with this? Unfortunately, I've found it a bit challenging to find a definitive answer through various searches.
Thanks for the help!
Test Code: test.cpp
#include <vector>
#include <iostream>
int main(void) {
std::vector<int> const v{ 1, 2, 3 };
std::cout << "Hello world\n";
std::cout << v[0] << "\n";
return 0;
}
Linux output
The following output is from Windows Subsystem for Linux, but the behavior is the same on a proper Linux install.
clang -v /mnt/c/Temp/test.cpp -I/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.1
"/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin/clang-8" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0 -I /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /mnt/c/Code/v3/Common/cpp/Clang/8 -ferror-limit 19 -fmessage-length 200 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-284194.o -x c++ /mnt/c/Temp/test.cpp -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
/usr/local/include
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include
/usr/include
End of search list.
In file included from /mnt/c/Temp/test.cpp:1:
In file included from /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/vector:273:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/__config:206:12: fatal error: 'features.h' file not found
# include <features.h>
^~~~~~~~~~~~
1 error generated.
Windows Output
clang -v c:\temp\test.cpp
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\bin
clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
"C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -v -resource-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0\\include" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\include\\c++\\v1" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\Catch2\\v2.7.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\GSL\\v2.0.0\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8" -ferror-limit 19 -fmessage-length 200 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\brownell\\AppData\\Local\\Temp\\test-9329b0.o" -x c++ "c:\\temp\\test.cpp" -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\lib\clang\8.0.0\include
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1
C:\Code\v3\Common\cpp\Common\Libraries\C++\Catch2\v2.7.0
C:\Code\v3\Common\cpp\Common\Libraries\C++\GSL\v2.0.0\include
End of search list.
In file included from c:\temp\test.cpp:1:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\vector:274:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\iosfwd:96:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
For linux
On linux clag will default to using gnu's implementation of the standard library which is libstdc++. To use llvm's implementation - libc++ - you first need to install it. On ubuntu, for instance: sudo apt install libc++-9-dev libc++abi-9-dev. You might need to add the apple repos. Follow these instructions for more systems and latest versions. Then you need to explicit specify it when compiling: -stdlib=libc++. Please see https://libcxx.llvm.org/docs/UsingLibcxx.html
For linking install lld (sudo apt install lld-9) then specify it when compiling with -fuse-ld=lld

Clang++ not seeing libc++

I've just installed clang++ and libc++ from https://github.com/llvm/llvm-project.git. While trying to run:
clang main.cpp -stdlib=libc++ -lc++abi
where main.cpp:
#include <iostream>
int main() {
std::cout << "main>" << std::endl;
}
I get an error:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
-v option's output:
clang version 9.0.0 (https://github.com/llvm/llvm-project.git 40046bc8430f0b90d76cef9e6cc62ccc2abcb0b0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/jakub/Documents/Programming/Projects/TraitNet/src -ferror-limit 19 -fmessage-length 93 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/main-48c930.o -x c++ main.cpp -faddrsig
clang -cc1 version 9.0.0 based upon LLVM 9.0.0svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/lib/clang/9.0.0/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
It probably has to do with the includes. I installed libc++ to /usr/include (eg. iostream could be found at /usr/include/c++/6/iostream). Is there a way of letting clang know where the files (iostream is not the only header it has complained about) are?
I fixed a similar issue by adding the right directory to the include search path.
This directory must match the version of libc++.
For example, if you installed the package libc++10-dev, you must add /usr/lib/llvm-10/include/c++/v1/.
Here is the invocation:
clang main.cpp -stdlib=libc++ -I/usr/lib/llvm-10/include/c++/v1/
If you're unsure what folder to use, you can use find to locate it:
$ find /usr/ -name iostream
/usr/include/c++/5/iostream
/usr/include/c++/7/iostream
/usr/include/c++/4.4/iostream
/usr/include/c++/8/iostream
/usr/include/c++/4.9/iostream
/usr/include/c++/10/iostream
/usr/include/c++/9/iostream
/usr/include/c++/4.8/iostream
/usr/include/c++/4.7/iostream
/usr/include/c++/4.6/iostream
/usr/lib/llvm-10/include/c++/v1/iostream

How to use header file <xmmintrin.h> with Yocto-generated SDK?

I have an issue with a Yocto-generated SDK: the header file xmmintrin.h is not found when trying to compile with the SDK. Example:
$ echo '#include <xmmintrin.h>' > t.cpp
$ $CXX $CXXFLAGS -no-canonical-prefixes -c t.cpp
t.cpp:1:10: fatal error: 'xmmintrin.h' file not found
$CXX points to the SDK's clang++.
The verbose output is:
$ $CXX $CXXFLAGS -no-canonical-prefixes -c t.cpp -v
clang version 6.0.0 (git://github.com/llvm-mirror/clang.git ff0c0d8ab3e316bb6e2741fedb3b545e198eab7a) (git://github.com/llvm-mirror/llvm.git 089d4c0c490687db6c75f1d074e99c4d42936a50)
Target: x86_64-poky-linux-musl
Thread model: posix
InstalledDir: /opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/x86_64-poky-linux-musl
Found candidate GCC installation: /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/lib//x86_64-poky-linux-musl/7.3.0
Found candidate GCC installation: /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/lib/gcc/x86_64-poky-linux-musl/7.3.0
Selected GCC installation: /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/lib//x86_64-poky-linux-musl/7.3.0
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/x86_64-poky-linux-musl/x86_64-poky-linux-musl-clang++" -cc1 -triple x86_64-poky-linux-musl -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name t.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -fmath-errno -mfpmath sse -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu core2 -target-feature +sse3 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /home/kamo7631/t.gcno -rpokyurce-dir /opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0 -isysroot /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl -internal-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include/c++/v1 -internal-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/local/include -internal-isystem /opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0/include -internal-externc-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/include -internal-externc-isystem /opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include -O2 -fdeprecated-macro -fdebug-compilation-dir /home/kamo7631 -ferror-limit 19 -fmessage-length 132 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o t.o -x c++ t.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/local/include"
ignoring nonexistent directory "/opt/poky-tiny/2.4.2/sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0/include"
ignoring nonexistent directory "/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include/c++/v1
/opt/poky-tiny/2.4.2/sysroots/core2-64-poky-linux-musl/usr/include
End of search list.
t.cpp:1:10: fatal error: 'xmmintrin.h' file not found
#include <xmmintrin.h>
^~~~~~~~~~~~~
1 error generated.
The header file is present as sysroots/x86_64-pokysdk-linux/usr/lib/clang/6.0.0/include/xmmintrin.h, but is not found anywhere in sysroots/core2-64-poky-linux-musl (the target sysroot).
What do I have to change in order to be able to use this and other header files from the SDK?
Please post output of
$CLANGCXX $CXXFLAGS -no-canonical-prefixes -c t.cpp -v
I think the problem is a bug in SDK where compiler include paths are looking for
compiler headers but in wrong directory. Maybe its pointing to sysroots/x86_64-pokysdk-linux/usr/bin/lib/clang/6.0.0/include
you can try to add -I ${OECORE_NATIVE_SYSROOT}/usr/lib/clang/6.0.0/include to your compiler cmdline. also make sure you have sources the SDK environment script which is at the top of SDK install dir, its name starts like this "environment-setup-"