make error: No such file or directory - linux-kernel

I am new to kernel module development. So I started with simple hello world kernel module
I am using "The Linux Kernel Module Programming Guide" book for the reference (it is addressing to kernel 2.6).
I installed kernel-devel and kenel headers with yum. I am using fedora 17.
I found that a symlink
/lib/modules/3.3.4-5.fc17.x86_64/build -> /usr/src/kernels/3.3.4-5.fc17.x86_64
Now, I have one hello-1.c (the simple kernel module and a Makefile in my working directory)
The Makefile is:
obj-m += hello-1.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
when in $make i get error:
make -C /lib/modules/3.3.4-5.fc17.x86_64/build M=/root/kerneldev modules
make: *** /lib/modules/3.3.4-5.fc17.x86_64/build: No such file or directory. Stop.
make: *** [all] Error 2
I make same program on Centos-5.x it run successfully , because the /lib/modules/3.3.4-5.fc17.x86_64/build was containing the actual module (not a symlink).
What should be problem ? why such difference?

The message
make: *** /lib/modules/3.3.4-5.fc17.x86_64/build: No such file or directory. Stop.
Is telling you that the directory path after the *** does not exist. Make issues this exact format of error when the -C directory doesn't exist. Other non-existent path situations will result in more words. For example, if the /lib/modules/3.3.4-5.fc17.x86_64/build directory does exist but it contains no makefile, make will specifically say no makefile found.
So the other answers are giving you ideas to help you create that directory with its proper contents.
And this answer is intended to also help people who have the above form of error message and for whom installing 'kernel-devel' will not help, by explaining the message itself.

I have few doubts like, where your issuing the make command.
Your current directory seems to be
M=/root/kerneldev
whether your hello-1.c is in /root/kerneldev folder.

try "yum install kernel-devel"(for kernel headers)

Related

kernel compile and menuconfig

I am a newer in linux and using ubuntu(4.4.0-64-generic) in vmware fusion. I am learning how to compile kernel. So, I downloaded the kernel(linux-4.4.52.tar.xz) from the kernel.org. But when I input make menuconfig, there are some errors.
root#ubuntu:/usr/src/linux-4.4.52# make menuconfig
HOSTCC scripts/basic/fixdep
In file included from /usr/include/x86_64-linux-gnu/bits/posix1_lim.h:160:0,
from /usr/include/limits.h:143,
from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:168,
from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/syslimits.h:7,
from /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h:34,
from scripts/basic/fixdep.c:114:
/usr/include/x86_64-linux-gnu/bits/local_lim.h:38:26: fatal error: linux/limits.h: No such file or directory
compilation terminated.
scripts/Makefile.host:91: recipe for target 'scripts/basic/fixdep' failed
make[1]: * [scripts/basic/fixdep] Error 1
Makefile:444: recipe for target 'scripts_basic' failed
make: * [scripts_basic] Error 2
I have installed headers files and done everything I can do. Someone can help me solve this problem?
You symbolic link is wrong; /usr/src/linux-4.4.0-64-generic/include/linux is the wrong directory and must not be linked to /usr/include/linux.
The kernel has two sets of headers: kernel-internal headers, and user API headers. The latter are inside the uapi directory, and they are what user-space program should see.
When you are compiling your own kernel, you can install the user-space headers of that kernel with make headers_install.
When you are using your distribution's kernel, you can just (re-)install the appropriate package (in your case, linux-headers-generic), and that will do the right thing as long as you do not muck around with those files afterwards.

How to rename a built-in linux kernel module?

I am trying to extend the built-in xfs module of linux kernel. Following this SO post, I am now able to compile it locally. But to avoid conflict with the existing kernel xfs module, I would like to rename my extension to, say xxfs, without changing the name of the source files.
I've found a related post, following which I changed the relevant lines in Makefile to:
obj-$(CONFIG_XFS_FS) += xxfs.o
xxfs-objs := xfs.o
But I got an error saying
make[1]: *** No rule to make target '/home/dev/tmp/xxfs/xfs.o', needed by '/home/dev/tmp/xxfs/xxfs.o'. Stop.
Makefile:1403: recipe for target '_module_/home/dev/tmp/xxfs' failed
make: *** [_module_/home/dev/tmp/xxfs] Error 2
make: Leaving directory '/usr/src/linux-headers-4.4.0-28-generic'
Environment:
Ubuntu 16.04 with kernel 4.4.0-28-generic.
EDIT
I got the xfs kernel module source file by
installing the linux kernel source with apt-get source linux-source-4.4.0
copy the linux-4.4.0/fs/xfs to another directory (merely for easy maintenance), currently /home/dev/tmp/xxfs
To compile the module, I run the command make -C /lib/modules/$(uname -r)/build M=$(pwd) modules from the /home/dev/tmp/xxfs directory, after which a xfs.ko will be generated in the same directory.
However after I change the following line in Makefile
obj-$(CONFIG_XFS_FS) += xfs.o
to
obj-$(CONFIG_XFS_FS) += xxfs.o
xxfs-objs := xfs.o
Everything else is not touched, but I am no longer able to compile the module with the same command.

No rule to make target error halfway down the make

On a Leopard Mac mini (PowerPC) I'm trying to compile Apple-GCC-3.3 which I got from https://opensource.apple.com/tarballs/gcc_os/gcc_os-1819.tar.gz
./configure gets completed w.o. any error but make gives the following errors:
When input only "make" it says
make: *** No rule to make target `all', needed by `default'. Stop.
When input make -f Makefile, the make starts fine but somewhere halfway down the process it stops with:
gcc tclAppInit.o -L/Users/macmini/Downloads/gcc_os-1819/tcl/unix -ltcl8.0 -lc \-o tclsh
make[1]: *** No rule to make target `all'. Stop.
make: *** [all-expect] Error 2
For this type of error, it's said that the tar might be dropping long filenames during the untar operation but I tried with different versions of tar such as 1.14, 1.27 and the error is the same.
What should I do? Thanks.
!(http://i.hizliresim.com/Kl9rRJ.png)
(Just in case you may wonder why I want to compile GCC-3.3, it's because it's needed to compile GIMP on PowerPC Macs)
Problem solved. It turned really hard to compile GCC-3.3 from source, so I made it easy and installed it from XCode 3.1 DVD, under the Packages directory where GCC-3.3.pkg was present.
Now the GIMP can be compiled.
Summary: It's a good idea to install the Apple's compiler group of programs from the XCode DVD.
Thanks.

Trouble Making Spooles

I am trying to make Spooles 2.2-9 on Mint Maya linux distro and I get the following error.
aaron#atown ~/Downloads/spooles $ sudo make global
cd A2/src ; make -f makeGlobalLib
make[1]: Entering directory `/home/aaron/Downloads/spooles/A2/src'
makeGlobalLib:19: warning: overriding commands for target `.c.o'
../../Make.inc:90: warning: ignoring old commands for target `.c.o'
/usr/lang-4.0/bin/cc -c -O basics.c -o A2_basics.o
make[1]: /usr/lang-4.0/bin/cc: Command not found
make[1]: *** [basics.o] Error 127
make[1]: Leaving directory `/home/aaron/Downloads/spooles/A2/src'
make: *** [global] Error 2
I am new to linux so any help would be most useful.Thanks
Have you tried installing it from your software package manager? I know that package is provided by Ubuntu and Debian, and Mint is a derivative so it should have it available for installation. No need to build it yourself.
If you do want to compile it yourself, first note you should never build software as root (don't prefix the make command with sudo). It's possible that if there's an install step you'll need to run that as root, but generally not the build.
Second it looks like by default this package is configured to build on OSX (I think /usr/lang-4.0/bin/cc is an OSX path... maybe?). In any event, that's not where the compiler lives on Linux: try this to override the compiler:
make CC=gcc global
It's also possible that your system does not have a compiler installed. If you get an error from the above then use your software package manager to install the gcc package.

User Mode Linux - Installing a module error

I am trying to run 'make' on a module in User Mode Linux to install a simple makefile. Here is my make file:
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
When I run this in User Mode Linux I get the following error:
make[1]: Entering directory `/lib/modules/2.6.28/build'
make[1]: *** No rule to make target `modules'. Stop.
make[1]: Leaving directory `/lib/modules/2.6.28/build'
make: *** [default] Error 2
The problem is that no files are present under /lib/modules/. There's no directory for 2.6.28 or build. From what I've read, these should be symlinks to /usr/src, but under /usr/src, I don't see any files under that either.
Sources and headers of your UML kernel must be used to compile module for it.
You can compile it either inside UML or just in main system, but you must to use UML's kernel's headers and build scripts
You need to build and install the version of the kernel you are compiling for. Get the source from kernel.org, configure (I think make menuconfig picks the config up from the running kernel), build, and install it. You can do the build in your home directory under regular user, then of course you would need root to install it.
Edit:
Just in case you missed this - here's User Mode Linux HOWTO. It contains specific items for building and installing kernel and modules. Hope this helps.

Resources