STL headers not found when using clang with `--gcc-toolchain`

We cross compile our project by using llvm with the gcc backend (--gcc-toolchain). cfamily scanner seems to not recognize that parameter and does not realise the STL headers live in there.

So with compile command similar to:

<clang_path>/bin/clang++
 --sysroot=<sysroot_path>
 --gcc-toolchain=<gcc_path>
 --target=arm-linux-gnueabihf
 -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9
 file.cpp

clang find the STL headers in <gcc_path>/arm-linux-gnueabihf/include/c++/13.3.0

But cfamily reports this:

Probing compiler: [<clang_path>/bin/clang++, -x, c++, --std, c++17, -target, arm-linux-gnueabihf, --sysroot=<sysroot_path>, -mfloat-abi=hard, -mfpu=neon, -v, -dM, -E, -]
...
clang version 17.0.6
Target: arm-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/local/adyen/clang+llvm/bin
 (in-process)
"<clang_path>/clang-17" -cc1 -triple armv6kz-unknown-linux-gnueabihf -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name - -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu arm1176jzf-s -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature -fp16 -target-feature -vfp4 -target-feature -vfp4d16 -target-feature -vfp4d16sp -target-feature -vfp4sp -target-feature -fp-armv8 -target-feature -fp-armv8d16 -target-feature -fp-armv8d16sp -target-feature -fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -sha2 -target-feature -aes -target-feature -fp16fml -target-feature +strict-align -target-abi aapcs-linux -mfloat-abi hard -Wunaligned-access -debugger-tuning=gdb -target-linker-version 1015.7 -v -fcoverage-compilation-dir=/Users/michale/workspace/vos/builds/vos2/test-ccache -resource-dir <clang_path>lib/clang/17 -isysroot <sysroot_path> -internal-isystem <clang_path>lib/clang/17/include -internal-isystem <sysroot_path>/usr/local/include -internal-externc-isystem <sysroot_path>/include -internal-externc-isystem <sysroot_path>/usr/include -std=c++17 -fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -dM -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o - -x c++ -

clang -cc1 version 17.0.6 based upon LLVM 17.0.6 default target arm64-apple-darwin23.6.0
#include "..." search starts here:
#include <...> search starts here:
 <clang_path>/lib/clang/17/include
 <sysroot_path>/usr/local/include
 <sysroot_path>/include
 <sysroot_path>/usr/include
End of search list.

With this search list missing <gcc_path>/arm-linux-gnueabihf/include/c++/13.3.0, analysis of the file brings this error:

The analyzer was not able to find file
  string
  included from file file.cpp

SonarQube: v10.6
SonarScanner CLI 6.1.0.4477

Hello @mejdys.adyen ,

Unfortunately, --gcc-toolchain is not forwarded to the compiler when probing. I have created a ticket to add support for it,

https://sonarsource.atlassian.net/browse/CPP-5738

In the meantime, can you try doing the wrapped compilation with the environment variable CPLUS_INCLUDE_PATH pointing to <gcc_path>/arm-linux-gnueabihf/include/c++/13.3.0 ? It should not change the compiler behavior (it is going to look there anyway), but it will influence the probe.

Let me know if it helps.

Thanks for the quick suggestion and raising an issue. Luckily, we have another workaround possible, we still have a gcc-only setup, which we will lean on for now. I will keep an eye on the ticket you raised. Thanks!

1 Like