I am trying to compile a simple helloworld module on my Raspberry Pi B+ under the 3.18.7+ Kenel. I did it after THIS tutorial. When I try to build my module I have this error :

make[1]: *** /lib/modules/3.18.7+/build: No such file or directory.  Stop

When I go to my /lib/modules/3.18.7+/build directory I have the following files :


As you can see, there is no build directory. I made some researches on the internet so I find that I have to made a link to the kernel source tree used to build the modules, by using this command

ln -s /path/to/kernel/source  /lib/modules/3.18.7+/build

So I did so by typing the following command :

ln -s /usr/src/linux-kbuild-3.18  /lib/modules/3.18.7+/build

Even if I did that, I still got the same error that the one in the beginning. In the directory /usr/src/linux-kbuild-3.18 I have only a scripts directory containing those files :

basic             gcc-goto.sh                        kallsyms        Makefile.clean      makelst            namespace.pl     ver_linux
checkincludes.pl  gcc-version.sh                     Kbuild.include  Makefile.extrawarn  mksysmap           patch-kernel
checkstack.pl     gcc-x86_32-has-stack-protector.sh  kconfig         Makefile.host       mkuboot.sh         pnmtologo
checkversion.pl   gcc-x86_64-has-stack-protector.sh  kernel-doc      Makefile.lib        mkversion          recordmcount
conmakehash       gen_initramfs_list.sh              Lindent         Makefile.modinst    mod                recordmcount.pl
depmod.sh         genksyms                           Makefile.build  Makefile.modpost    module-common.lds  setlocalversion

If there is any solution it will be great, thanks

3 Answers 3


That /usr/src/linux-kbuild-3.18 does not appear to be a kernel source directory; it is possibly some related tools provided by the distro. A kernel source tree looks like this.

Normal linux distros, including Debian, always have a source package available corresponding to their kernels. Unfortunately with Raspbian this is not the case, you must get it from github:

git clone https://github.com/raspberrypi/linux.git

Beware this is almost 2 GB of stuff. Modules must be built against exactly the same source version as the kernel. Generally this is pretty straightforward, but I am not sure if the '+' suffix sometimes used with the raspberry pi kernels has any significance in this sense. The versions are given in the commit comment on Makefile, e.g.;

> git log Makefile
commit c963de6d8caec6278c0dde76831f9fdab5bace52
Author: Sasha Levin <[email protected]>
Date:   Mon Apr 20 15:48:02 2015 -0400

    Linux 3.18.12

    Signed-off-by: Sasha Levin <[email protected]>

commit f154a14e3efa547025d014d0a3f29396f03b1f74
Author: Sasha Levin <[email protected]>
Date:   Fri Apr 3 22:46:37 2015 -0400

    Linux 3.18.11

    Signed-off-by: Sasha Levin <[email protected]>

commit 96e199f1751e707a7a8c04d9b079f84df2e0d4ff
Author: Sasha Levin <[email protected]>
Date:   Mon Mar 23 21:05:12 2015 -0400

    Linux 3.18.10

    Signed-off-by: Sasha Levin <[email protected]>


3.18.7 turns out to be a17f9bf1f7cd3412b9920577a7c0ec34cb81b233, so:

> git reset --hard a17f9bf1f7cd3412b9920577a7c0ec34cb81b233

Should take you back to that. I believe in order to make this work with an external module, you first need to:

make bcmrpi_defconfig
make modules_prepare

I don't think you have to do more than that but if you do need to build the kernel itself -- which will take hours on a pi -- you might as well switch to back to the latest version:

make mrproper
git reset --hard 'HEAD@{1}'
make bcmrpi_defconfig
make modules_install

You would then need to install the kernel:

cp arch/arm/boot/bzImage /boot/linux-3.18-12

And edit /boot/config.txt:

  • Thank you for the answer. Yes that what I tought because for linux for computer there is always the sources! I have to the 'git reset --hard a17f9bf1f7cd3412b9920577a7c0ec34cb81b233' from the raspberry, that's it ?
    – EngineerN
    Commented May 4, 2015 at 14:21
  • You have to download the repository first (git clone), which will probably take 20-30 minutes on a pi. Then you do that reset inside the tree. Git is a version control system which allows you to roll an entire directory hierarchy back to a previous state. Currently, the kernel version in the repo is 3.18.12, but they have to match exactly, so unless you want to build a kernel, you need to roll back to match the one you have; I've edited some other stuff in there about this.
    – goldilocks
    Commented May 4, 2015 at 14:47
  • Thank you for your help but I did it with archlinux instead
    – EngineerN
    Commented May 29, 2015 at 8:38
  • 1
    raspberrypi.stackexchange.com/a/38991/26266 is a similar answer
    – x29a
    Commented Apr 13, 2016 at 14:47

So I got a solution by using ARCHLINUX instead of Raspbian. It's a great distribution. After installing it on the raspberry, you need to update tour system with pacman -Syu, after that you need to reboot your system with reboot. You write your kernel module and your Makefile. When you'll try to compile your module you will have many missing packages which didn't get installed while updating the system. You will need to install them pacman -S base-devel and that's it ! Thanks for your help guys !!


You can install the source corresponding to the current kernel using rpi-source

Using a raspbian wheezy you will need the following steps:

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
echo deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free | sudo tee /etc/apt/sources.list.d/jessie.list
sudo apt-get update
sudo apt-get install -y gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
sudo rpi-source

I guess with a jessie distribution it is simpler (gcc upgrade should not be needed), but last time I tried to run a dist-upgrade the system was not booting anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.