Linux make build no such file or directory

error: stdio.h: No such file or directory error during make

I’m trying to compile the following program in Ubuntu. But I keep getting the error: «stdio.h: No such file or directory» error.

obj-m += hello.o all: make -I/usr/include -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 

3 Answers 3

Your way of building your program is the way to build kernel module and not c program application. and stdio.h does not exist in the environment of the kernel development so that’s why you get the error:

error: "stdio.h: No such file or directory" error 

1) If you want to build a linux application then your Makefile is wrong:

You should modify your Makefile

Use the following Makefile:

all: hello test: test.c gcc -o hello hello.c clean: rm -r *.o hello 

2) If you want to build a kernel module then your c code is wrong

  • YOU CAN NOT use stdio.h in the kernel space development. Itdoes not exist in the environment of the kernel development so that’s why you get the error
  • YOU CAN NOT use main() in the kernel module C code
  • YOU CAN NOT use printf() in the kernel module C code

INSTEAD of using stdio.h , you have to use the following include

#include /* Needed by all modules */ #include /* Needed for KERN_INFO */ 

INSTEAD of using int main() < , you have to use

INSTEAD of using printf() use printk()

Use the following hello module instead of your hello code

/* * hello-1.c - The simplest kernel module. */ #include /* Needed by all modules */ #include /* Needed for KERN_INFO */ int init_module(void) < printk(KERN_INFO "Hello world 1.\n"); /* * A non 0 return means init_module failed; module can't be loaded. */ return 0; >void cleanup_module(void)

Please refer to the following link for more detail about kernel module development

Читайте также:  Драйверы устройств linux windows

Источник

/lib/modules/. /build: No such file or directory [дубликат]

Пытался установить драйвера по инструкции для сетевого адаптера TP-Link Archer T1U скачанные с официального сайта TP-Link’a и словил ошибку:

root@kali:~/Desktop/Archer_T1U_V1_150909/Driver# make make -C UTIL/ osutil make[1]: Entering directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL' cp -f os/linux/Makefile.6.util /root/Desktop/Archer_T1U_V1_150909/Driver/UTIL/os/linux/Makefile make -C /lib/modules/4.14.0-kali3-amd64/build SUBDIRS=/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL/os/linux modules make[2]: Entering directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL' make[2]: *** /lib/modules/4.14.0-kali3-amd64/build: No such file or directory. Stop. make[2]: Leaving directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL' Makefile:527: recipe for target 'osutil' failed make[1]: *** [osutil] Error 2 make[1]: Leaving directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL' Makefile:3: recipe for target 'all' failed make: *** [all] Error 2 
root@kali:~/Desktop/Archer_T1U_V1_150909/Driver# make install make -C UTIL/ install_util make[1]: Entering directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL' make -C /root/Desktop/Archer_T1U_V1_150909/Driver/UTIL/os/linux -f Makefile.6.util install make[2]: Entering directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL/os/linux' install -d /lib/modules/4.14.0-kali3-amd64/kernel/drivers/net/wireless/ install -m 644 -c mt7650u_sta_util.ko /lib/modules/4.14.0-kali3-amd64/kernel/drivers/net/wireless/ install: cannot stat 'mt7650u_sta_util.ko': No such file or directory Makefile.6.util:50: recipe for target 'install' failed make[2]: *** [install] Error 1 make[2]: Leaving directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL/os/linux' Makefile:490: recipe for target 'install_util' failed make[1]: *** [install_util] Error 2 make[1]: Leaving directory '/root/Desktop/Archer_T1U_V1_150909/Driver/UTIL' Makefile:16: recipe for target 'install' failed make: *** [install] Error 2 
root@kali:~/Desktop/Archer_T1U_V1_150909/Driver# uname -a Linux kali 4.14.0-kali3-amd64 #1 SMP Debian 4.14.12-2kali1 (2018-01-08) x86_64 GNU/Linux 

Источник

make: *** /lib/modules/2.6.32-279.el6.x86_64/build: No such file or directory. Stop

Is kernel-devel the same version as your running kernel ? Run rpm -q kernel-devel and uname -r , the version numbers needs to be the same.

5 Answers 5

If your problem is like the one I was having (see below), it seems the kernel development package isn’t installed.

Original Message

I am having the same problem. But, interestingly, when I ls-l on the parent directory to the «missing directory» (so, ls -l /lib/modules/2.6.32-431.el6.x86_64/) it shows that build is a broken link pointing to /usr/src/kernels/2.6.32-431.el6.x86_64, but /usr/src/kernels/ is empty.

So, I don’t know if this is much help, but hopefully it gives someone else a better idea of what’s wrong.

[root@xx libreswan-3.7]# ls -l /lib/modules/2.6.32-431.el6.x86_64/ total 3524 lrwxrwxrwx. 1 root root 46 Dec 12 13:42 build -> ../../../usr/src/kernels/2.6.32-431.el6.x86_64 drwxr-xr-x. 2 root root 4096 Nov 21 22:41 extra drwxr-xr-x. 11 root root 4096 Dec 12 13:42 kernel -rw-r--r--. 1 root root 589679 Dec 12 13:43 modules.alias . -rw-r--r--. 1 root root 851070 Dec 12 13:43 modules.usbmap lrwxrwxrwx. 1 root root 5 Dec 12 13:42 source -> build drwxr-xr-x. 2 root root 4096 Nov 21 22:41 updates drwxr-xr-x. 2 root root 4096 Dec 12 13:42 vdso drwxr-xr-x. 2 root root 4096 Nov 21 22:41 weak-updates [root@xx libreswan-3.7]# ls /usr/src/kernels/ [root@xx libreswan-3.7]# 

Notice that the «source» link is also broken because it points to build.

Читайте также:  Linux mint upgrade kernel

Источник

Ubuntu make fails with No such file or directory /lib/modules/3.4.0/build

But I am confused by the error because the location apparently exists:

root@ChrUbuntu:/lib/modules/3.4.0# ls -la total 820 lrwxrwxrwx 1 root root 105 Feb 8 17:01 build -> /build/x86-mario/tmp/portage/sys-kernel/chromeos-kernel-3.4-r996/work/chromeos-kernel-3.4/build/x86-mario 

I modified the Makefile and I got the CP210x.ko driver to build. Unfortunately, now I need to build the usbserial driver too and I can’t find a download for that one.

This seems relevant, but I’m using ChrUbuntu, so I’m not sure what changes to make. ubuntuforums.org/showthread.php?t=1612392

I’m giving up; too many unknowns. ChrUbuntu is based on Ubuntu 12.04 but it uses kernel 3.4. I’m running into too many obstacles given that I have no experience with this.

@slm you said you intalled the kernel headers. Which version? ChrUbuntu uses a custom kernel, version 3.4.0. The Ubuntu repos don’t have matching headers for that kernel, as far as I know.

3 Answers 3

Figured out the steps to compile this kernel module. The version on the website, silabs.com is apparently too old to be used with newer kernels (3.4+).

I was able to compile a newer version of the file, cp210x.c , that I found over on kernel.org for my particular version of the kernel, using the Makefile provided in the VCP Driver Source.

Building cp210x for your kernel version

baseline your kernel

First make note of your major & minor numbers for your kernel you have (i.e. 3.4, 3.5, etc.).

Incidentally I’m on Ubuntu 12.10:

$ lsb_release -r Release: 12.10 

Install the kernel headers & build tools for your kernel version:

sudo apt-get install linux-headers-$(uname -r) build-essential 

Get the VCP bundle from silabs.com

Now make yourself a little work area for all this:

mkdir -p $HOME/cp210x && cd $HOME/cp210x 

Download the VCP Driver Source:

wget http://www.silabs.com/Support%20Documents/Software/Linux_3.x.x_VCP_Driver_Source.zip unzip Linux_3.x.x_VCP_Driver_Source.zip cd Linux_3.x.x_VCP_Driver_Source mv cp210x.c cp210x.c_orig 

Get kernel.org cp210x.c

Now download the appropriate version of cp210x.c for your kernel:

$ wget https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/plain/drivers/usb/serial/cp210x.c?h=linux-3.5.y -O cp210x.c 

Compile

Now we compile using make :

$ make make -C /lib/modules/3.5.0-19-generic/build M=/home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source modules make[1]: Entering directory `/usr/src/linux-headers-3.5.0-19-generic' CC [M] /home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source/cp210x.o Building modules, stage 2. MODPOST 1 modules CC /home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source/cp210x.mod.o LD [M] /home/manny/cp210x/Linux_3.x.x_VCP_Driver_Source/cp210x.ko make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-19-generic' 

Deploy

Now move any pre-existing cp210x.ko kernel out of the way:

sudo mv /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko.orig 

Now copy the newly built kernel module, cp210x.ko in it’s place:

sudo cp cp210x.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/cp210x.ko 

Load

Now make sure the previous cp210x.ko kernel module wasn’t loaded:

Читайте также:  Сменить часовой пояс линукс

Now let’s load our new cp210x.ko module:

Test

Confirm that it loaded correctly:

$ lsmod |grep cp210x cp210x 21822 0 usbserial 42355 1 cp210x 

Also check dmesg for any issues:

$ dmesg | tail . . [979772.614394] usbcore: registered new interface driver usbserial [979772.614410] usbcore: registered new interface driver usbserial_generic [979772.614456] USB Serial support registered for generic [979772.614461] usbserial: USB Serial Driver core [979772.614810] usbcore: registered new interface driver cp210x [979772.614822] USB Serial support registered for cp210x 

Compiling usbserial kernel module

The OP asked about how to accomplish compiling the usbserial.ko module as well, given it’s needed by the applications in order to make use of the cp210x kernel module. Here are those instructions.

First make note of which kernel version you’re using:

So we’re using 3.5.0, next install the kernel source:

sudo apt-get install linux-source-3.5.0 

Now let’s make ourselves a work area:

mkdir -p $HOME/src && cd $HOME/src 

Unpack the kernel source into our work area:

tar jxvf /usr/src/linux-source-3.5.0.tar.bz2 

Now let’s compile usbserial.ko :

$ cd linux-source-3.5.0/drivers/usb/serial $ make -C /usr/src/linux-headers-`uname -r` M=`pwd` modules make: Entering directory `/usr/src/linux-headers-3.5.0-19-generic' CC [M] /root/src/linux-source-3.5.0/drivers/usb/serial/usb-serial.o . . LD [M] /root/src/linux-source-3.5.0/drivers/usb/serial/usbserial.o . . CC /root/src/linux-source-3.5.0/drivers/usb/serial/usbserial.mod.o LD [M] /root/src/linux-source-3.5.0/drivers/usb/serial/usbserial.ko . . make: Leaving directory `/usr/src/linux-headers-3.5.0-19-generic' 

Check that usbserial.ko was built:

ls -l |grep usbserial -rw-r--r-- 1 root root 74822 May 15 09:20 usbserial.ko -rw-r--r-- 1 root root 4120 May 15 09:20 usbserial.mod.c -rw-r--r-- 1 root root 8840 May 15 09:20 usbserial.mod.o -rw-r--r-- 1 root root 74724 May 15 09:20 usbserial.o 

Now let’s install it, load it, and test it:

# move old driver out of the way $ mv /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/usbserial.ko.orig # copy newly built one in $ cp usbserial.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial/. # confirm `usbserial.ko` isn't loaded $ lsmod | grep usbserial $ # load it $ modprobe usbserial # confirm $ lsmod |grep usbserial usbserial 42355 0 # check dmesg log $ dmesg | tail -4 [1195955.210920] usbcore: registered new interface driver usbserial [1195955.210970] usbcore: registered new interface driver usbserial_generic [1195955.211002] USB Serial support registered for generic [1195955.211069] usbserial: USB Serial Driver core 

References

Источник

Оцените статью
Adblock
detector