riscv-software-src / riscv-tools

RISC-V Tools (ISA Simulator and Tests)
1.13k stars 446 forks source link

Build error: "features.h: No such file or directory" #186

Closed nihilscire closed 6 years ago

nihilscire commented 6 years ago

Hi, I've been trying to build the whole toolchain but the title error keeps coming up. It shows up when it's compiling riscv-pk, here's the details

Launching the build:

$ git submodule update --init --recursive
$ export RISCV=/path/to/install/riscv/toolchain
$ ./build.sh

Console output:

Starting RISC-V Toolchain build process
...
Removing existing riscv-pk/build directory
Configuring project riscv-pk
Building project riscv-pk
In file included from ../pk/file.h:6:0,
                 from ../pk/file.c:3:
/usr/include/x86_64-linux-gnu/sys/stat.h:25:10: fatal error: features.h: No such file or directory
 #include <features.h>
          ^~~~~~~~~~~~
compilation terminated.
make: *** [file.o] Error 1

Build.log:

checking build system type... x86_64-unknown-linux-gnu
checking host system type... riscv64-unknown-elf
checking for riscv64-unknown-elf-gcc... riscv64-unknown-elf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether riscv64-unknown-elf-gcc accepts -g... yes
checking for riscv64-unknown-elf-gcc option to accept ISO C89... unsupported
checking for riscv64-unknown-elf-g++... riscv64-unknown-elf-g++
checking whether we are using the GNU C++ compiler... yes
checking whether riscv64-unknown-elf-g++ accepts -g... yes
checking for riscv64-unknown-elf-ar... riscv64-unknown-elf-ar
checking for riscv64-unknown-elf-ranlib... riscv64-unknown-elf-ranlib
checking for riscv64-unknown-elf-readelf... riscv64-unknown-elf-readelf
checking for riscv64-unknown-elf-objcopy... riscv64-unknown-elf-objcopy
checking for a BSD-compatible install... /usr/bin/install -c
checking how to run the C preprocessor... riscv64-unknown-elf-gcc -E -traditional-cpp
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... no
configure: configuring default subproject : pk
configure: configuring default subproject : bbl
configure: configuring default subproject : softfloat
configure: configuring default subproject : dummy_payload
configure: configuring default subproject : machine
configure: configuring default subproject : util
configure: creating ./config.status
config.status: creating pk.mk
config.status: creating bbl.mk
config.status: creating softfloat.mk
config.status: creating dummy_payload.mk
config.status: creating machine.mk
config.status: creating util.mk
config.status: creating Makefile
config.status: creating config.h
riscv64-unknown-elf-gcc -MMD -MP -Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks  -DBBL_PAYLOAD=\"bbl_payload\" -DBBL_LOGO_FILE=\"bbl_logo_file\" -I. -I../pk -I../bbl -I../softfloat -I../dummy_payload -I../machine -I../util -c ../pk/file.c
Makefile:302: recipe for target 'file.o' failed

uname -a:

Linux xxx-desktop 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

with gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609

jim-wilson commented 6 years ago

On Tue, Mar 27, 2018 at 5:23 AM, nihilscire notifications@github.com wrote:

Building project riscv-pk In file included from ../pk/file.h:6:0, from ../pk/file.c:3: /usr/include/x86_64-linux-gnu/sys/stat.h:25:10: fatal error: features.h: No such file or directory

include

      ^~~~~~~~~~~~

compilation terminated. make: *** [file.o] Error 1

The error message suggests that you are using an x86 compiler to build riscv-pk.

riscv64-unknown-elf-gcc -MMD -MP -Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks -DBBL_PAYLOAD=\"bbl_payload\" -DBBL_LOGO_FILE=\"bbl_logo_file\" -I. -I../pk -I../bbl -I../softfloat -I../dummy_payload -I../machine -I../util -c ../pk/file.c Makefile:302: recipe for target 'file.o' failed

But the build log says it is a riscv64 compiler. So there appears to be something funny going on with your riscv64 compiler. I'd suggest manually running this command adding a -v option to look at the directories that the compiler searches for header files. You should see something like:

include "..." search starts here:

include <...> search starts here:

. ../pk ../bbl ../softfloat ../dummy_payload ../machine ../util /scratch/jimw/riscv-tools/riscv-tools/build-install/lib/gcc/riscv64-unknown-elf/7.2.0/include /scratch/jimw/riscv-tools/riscv-tools/build-install/lib/gcc/riscv64-unknown-elf/7.2.0/include-fixed /scratch/jimw/riscv-tools/riscv-tools/build-install/lib/gcc/riscv64-unknown-elf/7.2.0/../../../../riscv64-unknown-elf/include End of search list.

and there should be no x86 dirs in there. If there are, then your riscv64 compiler was configured wrong. Maybe you have some environment variables set that are confusing the gcc configure?

Jim

nihilscire commented 6 years ago

Thanks for the prompt reply. I ran the compilation command with -v option and here's the thing:

riscv64-unknown-elf-gcc -MMD -MP -Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks  -DBBL_PAYLOAD=\"bbl_payload\" -DBBL_LOGO_FILE=\"bbl_logo_file\" -I. -I../pk -I../bbl -I../softfloat -I../dummy_payload -I../machine -I../util -c -v ../pk/file.c
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
Target: riscv64-unknown-elf
Configured with: /home/***/polito/riscv-tools/riscv-gnu-toolchain/build/../riscv-gcc/configure --target=riscv64-unknown-elf --prefix=/home/***/riscv/toolchain --disable-shared --disable-threads --enable-languages=c,c++ --with-system-zlib --enable-tls --with-newlib --with-sysroot=/home/***/riscv/toolchain/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --src=../../riscv-gcc --enable-checking=yes --disable-multilib --with-abi=lp64d --with-arch=rv64imafdc 'CFLAGS_FOR_TARGET=-Os  -mcmodel=medlow'
Thread model: single
gcc version 7.2.0 (GCC) 
COLLECT_GCC_OPTIONS='-MMD' '-MP' '-Wall' '-Werror' '-D' '__NO_INLINE__' '-mcmodel=medany' '-O2' '-std=gnu99' '-Wno-unused' '-Wno-attributes' '-fno-delete-null-pointer-checks' '-D' 'BBL_PAYLOAD="bbl_payload"' '-D' 'BBL_LOGO_FILE="bbl_logo_file"' '-I' '.' '-I' '../pk' '-I' '../bbl' '-I' '../softfloat' '-I' '../dummy_payload' '-I' '../machine' '-I' '../util' '-c' '-v' '-march=rv64imafdc' '-mabi=lp64d'
 /home/***/riscv/toolchain/libexec/gcc/riscv64-unknown-elf/7.2.0/cc1 -quiet -v -I . -I ../pk -I ../bbl -I ../softfloat -I ../dummy_payload -I ../machine -I ../util -MMD file.d -MP -D __NO_INLINE__ -D BBL_PAYLOAD="bbl_payload" -D BBL_LOGO_FILE="bbl_logo_file" ../pk/file.c -quiet -dumpbase file.c -mcmodel=medany -march=rv64imafdc -mabi=lp64d -auxbase file -O2 -Wall -Werror -Wno-unused -Wno-attributes -std=gnu99 -version -fno-delete-null-pointer-checks -o /tmp/cct8ZLgz.s
GNU C99 (GCC) version 7.2.0 (riscv64-unknown-elf)
    compiled by GNU C version 5.4.0 20160609, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/home/***/riscv/toolchain/riscv64-unknown-elf/usr/local/include"
ignoring duplicate directory "/home/***/riscv/toolchain/riscv64-unknown-elf/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 ../pk
 ../bbl
 ../softfloat
 ../dummy_payload
 ../machine
 ../util
 /usr/include/x86_64-linux-gnu
 /home/***/riscv/toolchain/lib/gcc/riscv64-unknown-elf/7.2.0/include
 /home/***/riscv/toolchain/lib/gcc/riscv64-unknown-elf/7.2.0/include-fixed
 /home/***/riscv/toolchain/lib/gcc/riscv64-unknown-elf/7.2.0/../../../../riscv64-unknown-elf/include
End of search list.
GNU C99 (GCC) version 7.2.0 (riscv64-unknown-elf)
    compiled by GNU C version 5.4.0 20160609, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: b6af61774b69a27cf551f822e31e3613
In file included from ../pk/file.h:6:0,
                 from ../pk/file.c:3:
/usr/include/x86_64-linux-gnu/sys/stat.h:25:10: fatal error: features.h: No such file or directory
 #include <features.h>
          ^~~~~~~~~~~~
compilation terminated.

So the problem is in /usr/include/x86_64-linux-gnu which clearly shouldn't be there. I took a look at the environmental variables searching for that include directory with

$ env | grep -e "/usr/include/x86_64-linux-gnu"
CPLUS_INCLUDE_PATH=/usr/include/x86_64-linux-gnu
C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu

At this point I think you're right, the riscv64 compiler has been configured wrong. What can I do about it? If I build it once again, I am pretty sure the problem will come up as well...

jim-wilson commented 6 years ago

It looks like you set environment variables pointing at the x86 header files which should be unnecessary. Just unset those environment variables and the riscv compiler should start working.

It also looks like you are on a debian or ubuntu system using multiarch. When building a compiler for this target, you have to use --enable-multiarch when configuring gcc to get it to look in the right directories. Maybe you built your own gcc, didn't know that --enable-multiarch was required, and then set the environment variables to make it work?

nihilscire commented 6 years ago

Just unset those environment variables and the riscv compiler should start working.

Unsetting those variables, the toolchain compilation works fine.

Maybe you built your own gcc, didn't know that --enable-multiarch was required, and then set the environment variables to make it work?

Yes, that's exactly what happened. I didn't know that --enable-multiarch was required, so my gcc hasn't been configured for multiarch support. Maybe I am going to re-compile gcc with that option, as I will need it in the future.

You may close the issue. Thanks for your help.