Why does gcc search header files from non-exist folders?

6.6k views Asked by At

I am trying to build an open source project shark on CentOS 7, and get very weird build errors:

make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/sys/cdefs.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/wordsize.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/gnu/stubs.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/gnu/stubs-64.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/posix1_lim.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/local_lim.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/posix2_lim.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/types.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/typesizes.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/stdio_lim.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/sys_errlist.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/bits/errno.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/include/x86_64-linux-gnu/asm/errno.h', needed by `core/luv/luv.o'.
make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdint.h', needed by `core/luv/luv.o'.

After executing "gcc -E -v -" command, it outputs:

[root@centos shark]# gcc -E -v -
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140911/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/4.8.3/cc1 -E -quiet -v - -mtune=generic -march=x86-64
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.3/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/4.8.3/include
 /usr/local/include
 /usr/include
End of search list.

So the searching header file paths should be:

 /usr/lib/gcc/x86_64-redhat-linux/4.8.3/include
 /usr/local/include
 /usr/include

I can't work out how /usr/lib/gcc/x86_64-linux-gnu/4.8 and /usr/include/x86_64-linux-gnu come from. Could anyone give some clues?

2

There are 2 answers

0
rubenvb On BEST ANSWER

The author has uploaded files specific to his system to the source repository (see this issue report).

A solution is to find the offending files by doing a simple grep:

grep -R /usr/lib/gcc ./*

with the result (from a clean git clone)

./bpf/libbpf/bpf_load.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h \
./bpf/libbpf/bpf_load.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h \
./bpf/libbpf/bpf_load.d: /usr/include/elf.h /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdint.h \
./bpf/libbpf/bpf_load.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdbool.h \
./bpf/libbpf/libbpf.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h \
./bpf/libbpf/libbpf.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h \
./bpf/libbpf/libbpf.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdint.h /usr/include/stdint.h \
./bpf/bpf.lua:   local clang_cmd = string.format("clang -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include -I%s -I%s/arch/x86/include -I%s/arch/x86/include/generated/uapi -I%s/arch/x86/include/generated  -I%s/include -I%s/arch/x86/include/uapi -I%s/arch/x86/include/generated/uapi -I%s/include/uapi -I%s/include/generated/uapi -include %s/include/linux/kconfig.h %s -D__KERNEL__ -Wno-unused-value -Wno-pointer-sign -O2 -emit-llvm -x c -c %s -o %s", bpfinc, linuxinc, linuxinc, linuxinc, linuxinc, linuxinc, linuxinc, linuxinc, linuxinc, linuxinc, bpf.cargs_extra, srcfile, objfile)
./core/luv/luv.d: core/luajit/src/lua.h /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h \
./core/luv/luv.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h \
./core/luv/luv.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h \
./core/luv/luv.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h \
./core/luv/luv.d: /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdint.h /usr/include/stdint.h \
Binary file ./perf/libtraceevent.a matches
Binary file ./perf/libapikfs.a matches
Binary file ./perf/libperf.a matches

Removing the offending .d files (./bpf/libbpf/bpf_load.d, ./bpf/libbpf/libbpf.d, and ./core/luv/luv.d) worked for me.

6
Maxim Egorushkin On

I can't work out how /usr/lib/gcc/x86_64-linux-gnu/4.8 and /usr/include/x86_64-linux-gnu come from.

These headers files get installed with gcc. They are copies of the OS header files patched to compile cleanly with gcc. Some native OS header files (e.g. on Solaris, BSD) do not compile cleanly with gcc.


/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h',needed by core/luv/luv.o'.

The above says that luv.o was built when /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h was present. May be you built that .o file on another machine. Remove all .o and .d files or try make clean.