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

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-"

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

libstdc++ 10.3 doesn't provide <compare>

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?

Not able to Cross-compile and link source code using afl-clang-fast++

I am trying to fuzz a simple C++ code using afl plus plus clang compiler (llvm_mode). I'm able to fuzz the code and generate the ARM object file but it fails while linking. I guess i'm missing some linker options. Any help would be appreciated
Following is my command:
afl-clang-fast++ --target=arm-linux-gnueabihf --rtlib=compiler-rt --stdlib=libc++ -nostdinc++ -I${root}/include/c++/v1 -Wl,-L${root}/lib --sysroot ${sysroot} --gcc-toolchain=/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf -rpath ${root}/lib TestCodeX86toARM.cpp -o Test -v
root and sysroot values are as follows
root=/path/to/clang/install_dir
sysroot=/path/to/linarogcc/arm-linux-gnueabihf/libc
From the output, i can conclude that with the help of Linaro tool-chain, compilation is going through but linking is failing
Output:
afl-clang-fast++2.66d by <lszekeres#google.com> in CLASSIC mode
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: arm--linux-gnueabihf
Thread model: posix
InstalledDir: /usr/lib/llvm-6.0/bin
Found candidate GCC installation: /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0
Selected GCC installation: /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0
Candidate multilib: .;#m32
Selected multilib: .;#m32
"/usr/lib/llvm-6.0/bin/clang" -cc1 -triple armv6kz--linux-gnueabihf -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name TestCodeX86toARM.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu arm1176jzf-s -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi hard -fallow-half-arguments-and-returns -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v -nostdinc++ -resource-dir /usr/lib/llvm-6.0/lib/clang/6.0.0 -I /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/include/c++/v1 -D __AFL_HAVE_MANUAL_CONTROL=1 -D __AFL_COMPILER=1 -D FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -D __AFL_FUZZ_INIT()=int __afl_sharedmem_fuzzing = 1;extern unsigned int *__afl_fuzz_len;extern unsigned char *__afl_fuzz_ptr;unsigned char __afl_fuzz_alt[1024000];unsigned char *__afl_fuzz_alt_ptr = __afl_fuzz_alt; -D __AFL_FUZZ_TESTCASE_BUF=(__afl_fuzz_ptr ? __afl_fuzz_ptr : __afl_fuzz_alt_ptr) -D __AFL_FUZZ_TESTCASE_LEN=(__afl_fuzz_ptr ? *__afl_fuzz_len : (*__afl_fuzz_len = read(0, __afl_fuzz_alt_ptr, 1024000)) == 0xffffffff ? 0 : *__afl_fuzz_len) -D "__AFL_LOOP(_A)=({ static volatile char *_B __attribute__((used)); _B = (char*)\"##SIG_AFL_PERSISTENT##\"; __attribute__((visibility(\"default\"))) int _L(unsigned int) __asm__(\"__afl_persistent_loop\"); _L(_A); })" -D "__AFL_INIT()=do { static volatile char *_A __attribute__((used)); _A = (char*)\"##SIG_AFL_DEFER_FORKSRV##\"; __attribute__((visibility(\"default\"))) void _I(void) __asm__(\"__afl_manual_init\"); _I(); } while (0)" -isysroot /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc -internal-isystem /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/local/include -internal-isystem /usr/lib/llvm-6.0/lib/clang/6.0.0/include -internal-externc-isystem /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/include -internal-externc-isystem /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include -O3 -Wno-unused-command-line-argument -fdeprecated-macro -fdebug-compilation-dir /home/user/Tejas/CrossCopileTestCode -ferror-limit 19 -fmessage-length 87 -funroll-loops -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -load /usr/local/lib/afl/afl-llvm-pass.so -o /tmp/TestCodeX86toARM-c0d8ac.o -x c++ TestCodeX86toARM.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/local/include"
ignoring nonexistent directory "/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/include"
#include "..." search starts here:
#include <...> search starts here:
/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/include/c++/v1
/usr/lib/llvm-6.0/lib/clang/6.0.0/include
/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include
End of search list.
afl-llvm-pass++2.66d by <lszekeres#google.com> and <adrian.herrera#anu.edu.au>
[+] Instrumented 3 locations (non-hardened mode, ratio 100%).
"/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld" --sysroot=/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc -z relro -X --hash-style=gnu --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o Test /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib/crt1.o /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib/crti.o /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/crtbegin.o -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0 -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/lib/../lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/../lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib -L/home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib -L/home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib -rpath /home/user/Tejas/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/lib /tmp/TestCodeX86toARM-c0d8ac.o /usr/local/lib/afl/afl-llvm-rt.o -lc++ -lm /usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.builtins-armhf.a -lc /usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.builtins-armhf.a /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/7.5.0/crtend.o /home/user/Tejas/LLVM/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib/../lib/crtn.o
/usr/local/lib/afl/afl-llvm-rt.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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

Including header path with -I, but still not found

I'm having a strange error with clang. I'm attempting to build pandas and it's failing to build msgpack. I've added to my search path a folder which contains the file complex.h, and I'm passing the path to this folder as an argument with -I/nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include. However, clang is still failing to find it.
$ ls /nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include | grep complex
complex.h
$ clang -v -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -D__LITTLE_ENDIAN__=1 -Ipandas/src/klib -Ipandas/src -I/nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include -I/nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include -I/nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include/python2.7 -c pandas/msgpack.cpp -o build/temp.macosx-10.7-x86_64-2.7/pandas/msgpack.o
clang version 3.6.2 (tags/RELEASE_362/final)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
"/nix/store/3ipm9yr9jz4mcgc9n2fa85rwrjjk2bi0-clang-3.6.2/bin/clang-3.6" -cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -disable-free -disable-llvm-verifier -main-file-name msgpack.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -gdwarf-2 -dwarf-column-info -coverage-file /var/folders/wl/723blrkd0q70mdnf5flcvqsw00010q/T/pandas-build/pandas-0.16.2/build/temp.macosx-10.7-x86_64-2.7/pandas/msgpack.o -nostdsysteminc -resource-dir /nix/store/3ipm9yr9jz4mcgc9n2fa85rwrjjk2bi0-clang-3.6.2/bin/../lib/clang/3.6.2 -idirafter /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include -isystem /nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include -isystem /nix/store/whdp09gkfw7jvjp1l6i746cncf83p901-libc++-3.6.2/include -isystem /nix/store/9zqc1nvla9f3kbra4734wx7hdxafgzpc-openblas-0.2.14/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -D NDEBUG -D __LITTLE_ENDIAN__=1 -I pandas/src/klib -I pandas/src -I /nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include -I /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include -I /nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include/python2.7 -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks -O3 -Wall -Wstrict-prototypes -Wno-multichar -Wno-deprecated-declarations -fdeprecated-macro -fdebug-compilation-dir /var/folders/wl/723blrkd0q70mdnf5flcvqsw00010q/T/pandas-build/pandas-0.16.2 -ferror-limit 19 -fmessage-length 0 -fwrapv -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.7.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o build/temp.macosx-10.7-x86_64-2.7/pandas/msgpack.o -x c++ pandas/msgpack.cpp
clang -cc1 version 3.6.2 based upon LLVM 3.6.2 default target x86_64-apple-darwin13.4.0
#include "..." search starts here:
#include <...> search starts here:
pandas/src/klib
pandas/src
/nix/store/pv614rqz5vcvmh4gx1hma13cscbbn8a5-MacOSX10.9.sdk/Developer/SDKs/MacOSX10.9.sdk/usr/include
/nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include
/nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include/python2.7
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
/nix/store/8jnc2msdn8d386wni8pviji3g5zkld31-python-2.7.10/include
/nix/store/whdp09gkfw7jvjp1l6i746cncf83p901-libc++-3.6.2/include
/nix/store/9zqc1nvla9f3kbra4734wx7hdxafgzpc-openblas-0.2.14/include
/nix/store/3ipm9yr9jz4mcgc9n2fa85rwrjjk2bi0-clang-3.6.2/bin/../lib/clang/3.6.2/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
End of search list.
In file included from pandas/msgpack.cpp:252:
In file included from /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
In file included from /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from /nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1804:
/nix/store/8yvsx3drb1jv3l42kp5my9qjym2flqs2-python2.7-numpy-1.9.2/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by " \
^
In file included from pandas/msgpack.cpp:254:
pandas/src/msgpack/unpack.h:72:11: warning: comparison of constant 9223372036854775807 with expression of type 'uint32_t' (aka 'unsigned int') is always false [-Wtautological-constant-out-of-range-compare]
if (d > LONG_MAX) {
~ ^ ~~~~~~~~
pandas/msgpack.cpp:447:14: fatal error: 'complex' file not found
#include <complex>
^
2 warnings and 1 error generated.