I failed to find system interal header files (like <iostream>).
I can pass arguments to compile every time, but is there a way to change the default includes?
C:\WINDOWS\system32>clang++ -v -c -xc++ nul
clang version 16.0.0 (https://github.com/llvm/llvm-project.git e529c0a2a03fb4eb0ddffafe0ddc7a02059f74cc)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\languages\LLVM\bin
(in-process)
"D:\\languages\\LLVM\\bin\\clang++.exe" -cc1 -triple x86_64-pc-windows-msvc19.31.31107 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name nul -mrelocation-model pic -pic-level 2 -mframe-pointer=none -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 -v "-fcoverage-compilation-dir=C:\\WINDOWS\\system32" -resource-dir "D:\\languages\\LLVM\\lib\\clang\\16.0.0" -internal-isystem "D:\\languages\\LLVM\\lib\\clang\\16.0.0\\include" -internal-isystem "D:\\program tools\\Microsoft\\VC\\Tools\\MSVC\\14.25.28610\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt\\" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\shared" -fdeprecated-macro "-fdebug-compilation-dir=C:\\WINDOWS\\system32" -ferror-limit 19 -fmessage-length=120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.31.31107 -std=c++14 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o nul.o -x c++ nul
clang -cc1 version 16.0.0 based upon LLVM 16.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "D:\program tools\Microsoft\VC\Tools\MSVC\14.25.28610\include"
ignoring nonexistent directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\"
ignoring nonexistent directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um"
ignoring nonexistent directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared"
#include "..." search starts here:
#include <...> search starts here:
D:\languages\LLVM\lib\clang\16.0.0\include
End of search list.
just want to change these default nonexistent directory (I built clang from source)
The trick I use with GCC, which should also work with Clang, is using the environment variables C_INCLUDE_PATH/CPLUS_INCLUDE_PATH for compiler include paths and LIBRARY_PATH for linker library paths.
Related
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
I am attempting to cross-compile a C++ object file using the GNU ARM Embedded Toolchain libraries, and the Clang compiler. I cannot understand what is missing to successfully compile. Could someone help me to understand why clang cannot find the header files?
Here is my example program:
#include <algorithm>
extern "C" uint32_t * copy(
uint32_t const * first, uint32_t const * last, uint32_t * dest)
{
return std::copy(first, last, dest);
}
I invoke clang++ by specifying the target and sysroot:
$ clang++ --target=thumbv7m-none-eabi --sysroot "C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\arm-none-eabi" -c example.cpp -v
clang version 12.0.1
Target: thumbv7m-none-unknown-eabi
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
(in-process)
"C:\\Program Files\\LLVM\\bin\\clang++.exe" -cc1 -triple thumbv7m-none-unknown-eabi -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -nostdsysteminc -target-cpu cortex-m3 -target-feature +soft-float-abi -target-feature +strict-align -target-abi aapcs -mfloat-abi soft -fallow-half-arguments-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.1" -isysroot "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\arm-none-eabi" -internal-isystem "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\arm-none-eabi\\include\\c++\\v1" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.1\\include" -internal-isystem "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.07\\arm-none-eabi\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\source\\espresso\\components" -ferror-limit 19 -fmessage-length=226 -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o example.o -x c++ example.cpp
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\arm-none-eabi\include\c++\v1"
ignoring duplicate directory "C:\Program Files\LLVM\lib\clang\12.0.1\include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\LLVM\lib\clang\12.0.1\include
C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2021.07\arm-none-eabi\include
End of search list.
example.cpp:3:10: fatal error: 'algorithm' file not found
#include <algorithm>
^~~~~~~~~~~
1 error generated.
I would suspect a linker error (clang may not know how to find the correct libraries within the sysroot), however I am surprised clang cannot infer the location of the algorithm header given a sysroot.
Any suggestions?
Both clang and arm-none-eabi-gcc are in my path:
$ clang++ --version
clang version 12.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.07) 10.3.1 20210621 (release)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I've found that -sysroot doesn't solve the problem on my system and so - as suggested by the relevant Clang documentation - I've explicitly specified include paths using -isystem:
ifeq ($(toolchain),clang)
INCLUDE += -isystem "$(GCC_TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(GCC_TOOLCHAIN_VERSION)/arm-none-eabi"
INCLUDE += -isystem "$(GCC_TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(GCC_TOOLCHAIN_VERSION)"
INCLUDE += -isystem "$(GCC_TOOLCHAIN_DIR)/arm-none-eabi/include"
endif
Since the GCC header files use #include_next directives, the order of these is crucial.
For the time being I'm using gcc/g++ to link, so I'm yet to have to deal with any linking issues.
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?
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
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-"