Header file not found when using --gcc-toolchain

Dear all,

I have problems using Clang with --gcc-toolchain. I have built the “bare-metal” and “Linux” variants of the RISCV GNU toolchain project as multilib toolchains. Now, I am trying to compile a file test.cpp containing

#include <iostream>

int main (void)
{
    std::cout << "Hello World\n";
    return 0;
}

using the following command:

clang++ --gcc-toolchain=<path to riscv toolchain> -target riscv32-unknown-elf -mcpu=stx-fpu -o test test.cpp

(I have added support for -mcpu=stx-fpu to target the correct RISCV architecture rv32imafd I need.)

Using the bare-metal multilib toolchain, this works. However, if I use the Linux multilib toolchain, I get the following error:

In file included from .../riscv64-unknown-linux-gnu/include/c++/12.1.0/riscv64-unknown-linux-gnu/bits/c++config.h:655:
.../riscv64-unknown-linux-gnu/include/c++/12.1.0/riscv64-unknown-linux-gnu/bits/os_defines.h:39:10:
fatal error: 'features.h' file not found

The file exists in the toolchain installation, however it is not found.

I noticed the following things:

When using the bare-metal toolchain, Clang outputs

Found candidate GCC installation: /home/kai/home/software/riscv-gnu-toolchain-newlib/lib/gcc/riscv64-unknown-elf/12.1.0
Selected GCC installation: /home/kai/home/software/riscv-gnu-toolchain-newlib/lib/gcc/riscv64-unknown-elf/12.1.0
Candidate multilib: rv32imafd/ilp32d;@march=rv32imafd@mabi=ilp32d
Selected multilib: rv32imafd/ilp32d;@march=rv32imafd@mabi=ilp32d

and looks in several folders for header files. However, with the Linux toolchain, it outputs

Found candidate GCC installation: /home/kai/home/software/riscv-gnu-toolchain-linux/lib/gcc/riscv64-unknown-linux-gnu/12.1.0
Selected GCC installation: /home/kai/home/software/riscv-gnu-toolchain-linux/lib/gcc/riscv64-unknown-linux-gnu/12.1.0

so no multilib-related output is given, even though the toolchain is a multilib one. I also noticed that the directory structure of the Linux and bare-metal toolchains w.r.t. directories containing header files and libraries is different, e.g., there is a sysroot folder in the Linux toolchain and further directories are organized differently.

I also tried it with non-multilib Linux toolchain, this also does not work.

Any help on this would be greatly appreciated.

I solved this problem by realizing that -target riscv32-unknown-elf is wrong, since it indicates a bare-metal target. When changing this to -target riscv32-linux-gnu it correctly finds the necessary headers and libraries from the Linux GCC toolchain.