Clang cross-compilation with arm-none-eabi - c++

I want to do cross-compilation of following source file (Foo.cpp)
#include <cstdint>
int Foo()
{
uint32_t bar = 0;
return bar;
}
with i686-w64-mingw32 and arm-none-eabi on a Windows 10 system. Therefore I use following batch file
#echo off
set "PATH=C:/MinGW/i686-8.1.0-release-win32-dwarf-rt_v6-rev0/bin;%PATH%"
set "PATH=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update/bin;%PATH%"
set "PATH=C:/LLVM/7.0.0/bin;%PATH%"
clang++ ^
-c ^
-std=gnu++14 ^
-v ^
-target i686-w64-mingw32 ^
Foo.cpp ^
-o Foo.obj
#echo on
REM
REM
REM
REM
REM
#echo off
clang++ ^
-c ^
-std=gnu++14 ^
-v ^
-target arm-none-eabi ^
-march=armv6-m ^
-mcpu=cortex-m0 ^
-mthumb ^
-msoft-float ^
-mfloat-abi=soft ^
--sysroot=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update ^
Foo.cpp ^
-o Foo.o
pause
This produces following output
clang version 7.0.0 (tags/RELEASE_700/final)
Target: i686-w64-windows-gnu
Thread model: posix
InstalledDir: C:\LLVM\7.0.0\bin
"C:\\LLVM\\7.0.0\\bin\\clang++.exe" -cc1 -triple i686-w64-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Foo.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -dwarf-column-info -debugger-tuning=gdb -v -coverage-notes-file "c:\\Users\\Zlatan\\MKS\\Test\\Foo.gcno" -resource-dir "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\backward" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\8.1.0" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\8.1.0\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include\\c++\\8.1.0\\backward" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include\\c++\\8.1.0" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include\\c++\\8.1.0\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include\\c++\\8.1.0\\backward" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++\\i686-w64-mingw32" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\lib\\gcc\\i686-w64-mingw32\\8.1.0\\include\\c++\\backward" -internal-isystem "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0\\include" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\i686-w64-mingw32\\include" -internal-isystem "C:\\MinGW\\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\\include" -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir "c:\\Users\\Zlatan\\MKS\\Test" -ferror-limit 19 -fmessage-length 227 -fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdwarf-exceptions -fdiagnostics-show-option -fcolor-diagnostics -o Foo.obj -x c++ Foo.cpp
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target x86_64-pc-win32
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\i686-w64-mingw32"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\backward"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\8.1.0"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\8.1.0\i686-w64-mingw32"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include\c++\8.1.0\backward"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include\c++\8.1.0"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include\c++\8.1.0\i686-w64-mingw32"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include\c++\8.1.0\backward"
ignoring nonexistent directory "C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\lib\gcc\i686-w64-mingw32\8.1.0\include\c++
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\lib\gcc\i686-w64-mingw32\8.1.0\include\c++\i686-w64-mingw32
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\lib\gcc\i686-w64-mingw32\8.1.0\include\c++\backward
C:\LLVM\7.0.0\lib\clang\7.0.0\include
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\i686-w64-mingw32\include
C:\MinGW\i686-8.1.0-release-win32-dwarf-rt_v6-rev0\include
End of search list.
c:\Users\Zlatan\MKS\Test>REM
c:\Users\Zlatan\MKS\Test>REM
c:\Users\Zlatan\MKS\Test>REM
c:\Users\Zlatan\MKS\Test>REM
c:\Users\Zlatan\MKS\Test>REM
clang version 7.0.0 (tags/RELEASE_700/final)
Target: arm-none--eabi
Thread model: posix
InstalledDir: C:\LLVM\7.0.0\bin
"C:\\LLVM\\7.0.0\\bin\\clang++.exe" -cc1 -triple thumbv6m-none--eabi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Foo.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -mconstructor-aliases -nostdsysteminc -target-cpu cortex-m0 -target-feature +soft-float -target-feature +soft-float-abi -target-feature -crc -target-feature -dsp -target-feature -ras -target-feature -dotprod -target-feature -hwdiv-arm -target-feature -hwdiv -target-feature -fp-only-sp -target-feature -d16 -target-feature -vfp2 -target-feature -vfp3 -target-feature -fp16 -target-feature -vfp4 -target-feature -fp-armv8 -target-feature -neon -target-feature -crypto -target-feature +strict-align -target-abi aapcs -msoft-float -mfloat-abi soft -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tuning=gdb -v -coverage-notes-file "c:\\Users\\Zlatan\\MKS\\Test\\Foo.gcno" -resource-dir "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0" -isysroot C:/GNU-Tools-ARM-Embedded/7-2018-q2-update -internal-isystem "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\\include\\c++\\v1" -internal-isystem "C:\\LLVM\\7.0.0\\lib\\clang\\7.0.0\\include" -internal-isystem "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\\include" -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir "c:\\Users\\Zlatan\\MKS\\Test" -ferror-limit 19 -fmessage-length 227 -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o Foo.o -x c++ Foo.cpp -faddrsig
clang -cc1 version 7.0.0 based upon LLVM 7.0.0 default target x86_64-pc-win32
ignoring nonexistent directory "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\include\c++\v1"
ignoring nonexistent directory "C:/GNU-Tools-ARM-Embedded/7-2018-q2-update\include"
ignoring duplicate directory "C:\LLVM\7.0.0\lib\clang\7.0.0\include"
#include "..." search starts here:
#include <...> search starts here:
C:\LLVM\7.0.0\lib\clang\7.0.0\include
End of search list.
Foo.cpp:1:10: fatal error: 'cstdint' file not found
#include <cstdint>
^~~~~~~~~
1 error generated.
So for the i686-w64-mingw32 it's enough to put the location of the compiler to the path, but for arm-none-eabi the clang compiler can't find the cross-compilation headers.
Does somebody know how to configure clang for arm-none-eabi?
Why does this following happen?
Target: arm-none--eabi
Shouldn't it be?
Target: arm-none-eabi
Thanks!
Zlatan

I'm a bit late to the party but here are my two cents anyway:
The --sysroot option should be:
--sysroot=C:/GNU-Tools-ARM-Embedded/7-2018-q2-update/arm-none-eabi
You are missing the /arm-none-eabi part at the end. Clang looks for the directories bin, lib and include which are in the arm-none-eabi subdirectory of the toolchain (see the documentation here).
This should fix the "ignoring nonexistent directory" errors and the fatal error because of the missing standard library.

Related

Using makefile with pybind11

I am trying to manually compile a c++ project that uses pybind11. I am able to make it work but I don't understand one compilation problem.
Here is a minimal example: I have a folder containing the makefile and folders lib/, bin/ and src/. src/ contains the following files implementing a function that is just returns 1.
src/hi.hpp
#ifndef hi_hpp
#define hi_hpp
#include <stdio.h>
int get1();
#endif
src/hi.cpp
#include "hi.hpp"
int get1() {
return 1;
}
src/bind_hi.cpp
#include "hi.hpp"
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
namespace py = pybind11;
PYBIND11_MODULE( hi, m ) {
m.doc() = "doc"; // optional module docstring
m.def("get1", &get1, "get 1");
}
makefile (working)
CXX:=clang++
CXXFLAGS:=-Ofast -Wall -shared -std=c++11 -undefined dynamic_lookup -fPIC -I/Users/user/opt/anaconda3/include/python3.8 -I/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I/src
EXT:=$(shell python3-config --extension-suffix)
DEPS:= src/hi.cpp src/bind_hi.cpp
hi.$(EXT): $(DEPS)
$(CXX) $(CXXFLAGS) $(DEPS) -o lib/hi$(EXT) -v
clean:
#rm lib/*$(EXT)
.PHONY=clean
Here is the output I get during compilation:
clang++ -Ofast -Wall -shared -std=c++11 -undefined dynamic_lookup -fPIC -I/Users/user/opt/anaconda3/include/python3.8 -I/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I/src src/hi.cpp src/bind_hi.cpp -o lib/hi.cpython-38-darwin.so -v
clang version 10.0.0
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Users/user/opt/anaconda3/bin
"/Users/user/opt/anaconda3/bin/clang-10" -cc1 -triple x86_64-apple-macosx10.16.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hi.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 241.9 -v -resource-dir /Users/user/opt/anaconda3/lib/clang/10.0.0 -I /Users/user/opt/anaconda3/include/python3.8 -I /Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I /src -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -stdlib=libc++ -internal-isystem /Users/user/opt/anaconda3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Users/user/opt/anaconda3/lib/clang/10.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -Ofast -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/user/Documents/python_package_example -ferror-limit 19 -fmessage-length 158 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.16.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/xy/lcpszqt54bg9_4xnrhdk9j500000gp/T/hi-ffd9cb.o -x c++ src/hi.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include"
ignoring nonexistent directory "/src"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Users/user/opt/anaconda3/include/python3.8
/Users/user/opt/anaconda3/bin/../include/c++/v1
/Users/user/opt/anaconda3/lib/clang/10.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Users/user/opt/anaconda3/bin/clang-10" -cc1 -triple x86_64-apple-macosx10.16.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name bind_hi.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 241.9 -v -resource-dir /Users/user/opt/anaconda3/lib/clang/10.0.0 -I /Users/user/opt/anaconda3/include/python3.8 -I /Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include -I /src -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -stdlib=libc++ -internal-isystem /Users/user/opt/anaconda3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Users/user/opt/anaconda3/lib/clang/10.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -Ofast -Wall -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/user/Documents/python_package_example -ferror-limit 19 -fmessage-length 158 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.16.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/xy/lcpszqt54bg9_4xnrhdk9j500000gp/T/bind_hi-4642ed.o -x c++ src/bind_hi.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include"
ignoring nonexistent directory "/src"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Users/user/opt/anaconda3/include/python3.8
/Users/user/opt/anaconda3/bin/../include/c++/v1
/Users/user/opt/anaconda3/lib/clang/10.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
src/bind_hi.cpp:9:10: fatal error: 'pybind11/pybind11.h' file not found
#include <pybind11/pybind11.h>
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [hi..cpython-38-darwin.so] Error 1
This output deviates from that during successful compilation at the line:
ignoring nonexistent directory "/Users/user/opt/anaconda3/lib/python3.8/site-packages/pybind11/include"

Getting wchar.h file not found error for basic c++ program compiled with clang++ on riscv based simulator

We are trying to compile a basic c++ program in a QEMU simulator configured for RISCV architecture running on linux(busybear linux).
Below is the clang++ command using llvm c++ standard library.
/riscv_build/bin/clang++ --target=riscv64 -march=rv64gc hello.cpp -o hello --sysroot=/riscv_build/ -stdlib=libc++ -lc++abi
We have got below compilation errors.
"/riscv_build/bin/clang-12" -cc1 -triple riscv64-- -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -nostdsysteminc -target-feature +m -target-feature +a -target-feature +f -target-feature +d -target-feature +c -target-feature +relax -target-feature -save-restore -target-abi lp64d -msmall-data-limit 8 -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /riscv_build/lib/clang/12.0.1 -I /riscv_build/rv64/riscv64-unknown-linux-gnu/ -isysroot /riscv_build/ -internal-isystem /riscv_build/include/c++/v1 -internal-isystem /riscv_build/lib/clang/12.0.1/include -internal-isystem /riscv_build/include -fdeprecated-macro -fdebug-compilation-dir /riscv_build/bin -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -o /tmp/hello-623ee2.o -x c++ hello.cpp
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target riscv64-unknown-linux-gnu
ignoring duplicate directory "/riscv_build/lib/clang/12.0.1/include"
#include "..." search starts here:
#include <...> search starts here:
/riscv_build/rv64/riscv64-unknown-linux-gnu
/riscv_build/include/c++/v1
/riscv_build/lib/clang/12.0.1/include
/riscv_build/include
End of search list.
In file included from hello.cpp:1:
In file included from /riscv_build/include/c++/v1/iostream:37:
In file included from /riscv_build/include/c++/v1/ios:214:
In file included from /riscv_build/include/c++/v1/iosfwd:95:
/riscv_build/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
^~~~~~~~~
1 error generated.
So far as we can understand #include_next will look for another wchar.h file under "include/c++/v1/" but compiler is unable to find.
Help and guidance will be appreciated!

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?

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