fatal error: linux/compiler-gcc7.h: No such file or directory

15,080

Here are two issues:

  1. Kernel does not support PIC mode for compiling, details could be traced at this post. As @Joy noted, currently apt installed gcc5+ has PIE enabled by default, we need to add -fno-pie in to gcc option.

    Here I am following this fix, add following lines start from L774 of Makefile under the git repo you have cloned.

    # force no-pie for distro compilers that enable pie by default
    KBUILD_CFLAGS += $(call cc-option, -fno-pie)
    KBUILD_CFLAGS += $(call cc-option, -no-pie)
    KBUILD_AFLAGS += $(call cc-option, -fno-pie)
    KBUILD_AFLAGS += $(call cc-option, -no-pie)
    
    # optional, mute warnings on pointers signedness to speed up compilation
    KBUILD_CFLAGS += $(call cc-option, -Wno-pointer-sign)
    
  2. include/linux/compiler-gcc.h:121:1: fatal error: linux/compiler-gcc7.h, this basically stating that under folder include/linux of the git repo you have cloned, there is no such a file named compiler-gcc7.h. Currently under that folder exists only up to compiler-gcc5.h. Therefore a straight forward approach is to install and temporarily choose gcc-5 as the default compiler. Following:

    # install gcc-5
    sudo apt-get install gcc-5
    
    # use update-alternatives to switch default gcc version
    # register gcc-7
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60
    
    # choose gcc-5 at prompt
    update-alternatives --config gcc
    
    # now check gcc version, verify is using gcc-5
    gcc -v
    
    ## gcc version 5.5.0 20171010 (Ubuntu 5.5.0-12ubuntu1)
    

Installation instruction stated to install libnl-dev via

sudo apt-get install libnl-dev

yet libnl-dev seems no longer exists for 18.04. Consider use

sudo apt-get install libnl-3-dev

instead if you had trouble.

Finally you could switch back to gcc-7 after installation via

# choose gcc-7 at prompt
update-alternatives --config gcc
Share:
15,080

Related videos on Youtube

asdf60367134
Author by

asdf60367134

Updated on September 18, 2022

Comments

  • asdf60367134
    asdf60367134 over 1 year

    I am trying to install the Atheros CSI tool (provided installation instructions here), running Ubuntu 18.04.2 LTS on a Dell Inspiron 5570 laptop with a QCA9377 wireless adapter.

    I am able to do everything successfully that is listed under the "Prepare" section of "Compile the kernel" in the installation instructions. (There are some things not specified in the instructions that I was able to figure out to do, like installing make and gcc.) However, I am confused about the make menuconfig step and onwards. When I type make menuconfig in the Atheros-CSI-Tool folder, I press "Save" immediately, saving a file named .config, then "Exit" the menu.

    When I type make -j16 (I have 8 CPU-cores), this is the output:

      CHK     include/config/kernel.release
      CHK     include/generated/uapi/linux/version.h
      CC      scripts/mod/empty.o
      CC      scripts/mod/devicetable-offsets.s
    cc1: error: code model kernel does not support PIC mode
    cc1: error: code model kernel does not support PIC mode
    scripts/Makefile.build:258: recipe for target 'scripts/mod/empty.o' failed
    make[2]: *** [scripts/mod/empty.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    scripts/Makefile.build:153: recipe for target 'scripts/mod/devicetable-offsets.s' failed
    make[2]: *** [scripts/mod/devicetable-offsets.s] Error 1
    scripts/Makefile.build:403: recipe for target 'scripts/mod' failed
    make[1]: *** [scripts/mod] Error 2
    make[1]: *** Waiting for unfinished jobs....
    Makefile:555: recipe for target 'scripts' failed
    make: *** [scripts] Error 2
    make: *** Waiting for unfinished jobs....
    make: *** wait: No child processes.  Stop.
    

    When I then type make modules, this is the output:

      CHK     include/config/kernel.release
      CHK     include/generated/uapi/linux/version.h
      CHK     include/generated/utsrelease.h
      CC      arch/x86/purgatory/purgatory.o
    In file included from include/linux/compiler.h:54:0,
                     from include/uapi/linux/stddef.h:1,
                     from include/linux/stddef.h:4,
                     from ./include/uapi/linux/posix_types.h:4,
                     from include/uapi/linux/types.h:13,
                     from include/linux/types.h:5,
                     from arch/x86/purgatory/sha256.h:14,
                     from arch/x86/purgatory/purgatory.c:13:
    include/linux/compiler-gcc.h:121:1: fatal error: linux/compiler-gcc7.h: No such file or directory
     #include gcc_header(__GNUC__)
     ^~~~
    compilation terminated.
    scripts/Makefile.build:258: recipe for target 'arch/x86/purgatory/purgatory.o' failed
    make[1]: *** [arch/x86/purgatory/purgatory.o] Error 1
    arch/x86/Makefile:185: recipe for target 'archprepare' failed
    make: *** [archprepare] Error 2
    

    I tried to fix these errors I encountered by installing an old version of Ubuntu (14.04) from the archives, but Wi-Fi didn't work on my laptop under that OS (which is important since I am collecting data about Wi-Fi connections with the tool I'm trying to install). I also installed an old Linux kernel (4.1.10) from an online archive, but I encountered the same errors as shown above.

  • asdf60367134
    asdf60367134 almost 5 years
    Thank you for the response! I edited the Makefile and changed the gcc version as you suggested. (I was already able to figure out that I should install libnl-3-dev through a separate Ask Ubuntu answer.) When I run make -j16 in the terminal, I get warning: pointer targets in passing argument 4 of ‘skb_do_copy_data_nocache’ differ in signedness [-Wpointer-sign] and note: expected ‘const char *’ but argument is of type ‘const unsigned char *’ alternating in what seems like an infinite loop. (I had to close the terminal and kill the processes.) Any idea on what could be causing this?
  • Quar
    Quar almost 5 years
    @asdf60367134 the warning will repeat many times, due to its inside file sysfs.h and kernfs.h which has been used many places. A trick to monitor if the compilation is progressing is to check for lines like CC/LD [M] xxx/xxx/xxx.o or so. Since we are compiling a kernel, it takes longer than usual, as long as no error pops up.
  • asdf60367134
    asdf60367134 almost 5 years
    I let make -j16 run and this was the output. If you can't see in the image, undefined reference to `__stack_chk_fail' was printed a few times, along with Makefile:936: recipe for target 'vmlinux' failed.
  • Quar
    Quar almost 5 years
    @asdf60367134 While running on multiple builders, the one with 16.04LTS gcc-5.5, kernel 4.15.0-47-generic compiled without error (no changes need to be made, because gcc-5.5 did not have --enable-default-pie configured). I am still looking into solutions on 18.04 with gcc-5.6 ...
  • Quar
    Quar almost 5 years
    @asdf60367134 succeed on 18.04 with gcc-5.5 by adding no-pie flag to Assembler as well. Add KBUILD_AFLAGS += $(call cc-option, -no-pie) in Makefile as updated above.
  • asdf60367134
    asdf60367134 almost 5 years
    Before I saw your most recent comment, I tried changing my OS to Ubuntu 16.04 and was able to follow the original installation instructions successfully. I'm probably going to stay on this Ubuntu version for now but I know what to do if I want to change to 18.04. Thank you for your help!
  • Quar
    Quar almost 5 years
    @asdf60367134 Glad to help and best wishes to your studies :D