Add sysroot_include_flags to enable yocto sysroots #307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GCC and clang handle system paths and therefore sysroots very specifically. They include them strictly after any user provided includes.
We can see this for a simple compile test.
austin@localhost /tmp/compiletest
$ ls
a.out foo.cc stdio.h
austin@localhost /tmp/compiletest
$ cat foo.cc
int main(int argc, const char *const * argv) {
printf("Hello, World!\n");
return 0;
}
When we then compile with -v, clang (and gcc) will report what they did.
austin[264996] aschuh-3950x /tmp/compiletest
$ clang -v -isystem . foo.cc
Debian clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
Found CUDA installation: /usr/lib/cuda, version
"/usr/lib/llvm-14/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name foo.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -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 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/tmp/compiletest -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -isystem . -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/tmp/compiletest -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/foo-38bead.o -x c++ foo.cc
clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target x86_64-pc-linux-gnu ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/include"
.
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward
/usr/lib/llvm-14/lib/clang/14.0.6/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
foo.cc:4:3: error: use of undeclared identifier 'printf'
printf("Hello, World!\n");
^
1 error generated.
Which is correct and consistent with gcc. We can see that "-isystem ." gets included before the builtin directories. This is the same with --sysroot, when it works.
To enable distributions which don't match Clang and GCC's standard search path, we need to add the system includes after the "include_paths" feature.