LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-21-2014, 10:02 PM   #1
zerop
Member
 
Registered: Jul 2014
Posts: 65

Rep: Reputation: Disabled
Question after installed linux header in ubuntu 11, still have error linux/module.h no such fi


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

in home directory

i type

gcc -o cli cli.c
still got error

linux/module.h no such file or directory

then i search where is the source, i find it in /usr/src/

when search with find /usr/src/linux-headers-2.6.38-8-generic module.h

it run a list of file, and finally return no such file

how to compile c file which has module.h for kernel module programming with gcc
 
Old 07-22-2014, 03:43 AM   #2
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,841

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
11 is unsupported
https://wiki.ubuntu.com/Releases
 
Old 07-22-2014, 04:00 AM   #3
zerop
Member
 
Registered: Jul 2014
Posts: 65

Original Poster
Rep: Reputation: Disabled
how to see which version support this?

i use ubuntu 12.04 in virtual machine,

2.6.38-8/modules.h not found too

how to enable it to support, do i need to recompile the kernel?
 
Old 07-22-2014, 04:05 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
ubuntu 12.04 uses newer kernel, so you may need to try that. use the command locate to find module.h
 
Old 07-22-2014, 04:12 AM   #5
zerop
Member
 
Registered: Jul 2014
Posts: 65

Original Poster
Rep: Reputation: Disabled
/usr/src/linux-headers-3.8.0-29-generic/include/config/modules.h

i find this with locate result in above path

it exist, but compiler return not found

#include "/usr/src/linux-headers-3.8.0-29-generic/include/config/modules.h"
error too

Last edited by zerop; 07-22-2014 at 04:15 AM.
 
Old 07-22-2014, 04:14 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you must not do that, but configure the build system to locate kernel headers in /usr/src/linux-headers-3.8.0-29-generic/include
 
Old 07-22-2014, 04:43 AM   #7
zerop
Member
 
Registered: Jul 2014
Posts: 65

Original Poster
Rep: Reputation: Disabled
Question

i am newbie, how to configure the build system to locate the kernel headers ?

i follow oreilly 's book linux device driver to use the makefile, when type make, it said nothing to do

# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := cli.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

Last edited by zerop; 07-22-2014 at 04:51 AM.
 
Old 07-22-2014, 04:54 AM   #8
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,900

Rep: Reputation: 637Reputation: 637Reputation: 637Reputation: 637Reputation: 637Reputation: 637
As has already been pointed out Ubuntu 11 (there is nos such thing but anyway) is unsupported. Download Ubuntu 12.04 or 14.04 and install that. They both have 5 years of support so you can play around with them for may years to come.
 
Old 07-22-2014, 05:35 AM   #9
zerop
Member
 
Registered: Jul 2014
Posts: 65

Original Poster
Rep: Reputation: Disabled
Question

i am using ubuntu 12.04

i search for the error, then find a makefile below

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

however after make, return nothing to be done for 'all'

then i change to

obj-m += hello.o

hello.o:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


it result in another error

wonder@wonder-VirtualBox:~/layer$ make
cc -c -o hello.o hello.c
In file included from hello.c:3:0:
/usr/src/linux-headers-3.8.0-29-generic/include/linux/module.h:9:24: fatal error: linux/list.h: No such file or directory
compilation terminated.
make: *** [hello.o] Error 1



i use the make file in old version of oreilly book linux device driver

it can make to run, however got error

it use cc, but not gcc, is it modules programming can only use cc, not gcc?

make: *** No rule to make target `cli_init.o', needed by `cli.o'. Stop.
wonder@wonder-VirtualBox:~/layer$ make
cc -D__KERNEL__ -DMODULE -O -Wall -I/usr/src/linux-headers-3.8.0-29-generic/include -c -o cli.o cli.c
cli.c:1:0: warning: "MODULE" redefined [enabled by default]
<command-line>:0:0: note: this is the location of the previous definition
In file included from /usr/src/linux-headers-3.8.0-29-generic/include/linux/kernel.h:6:0,
from /usr/src/linux-headers-3.8.0-29-generic/include/linux/cache.h:4,
from /usr/src/linux-headers-3.8.0-29-generic/include/linux/time.h:4,
from /usr/src/linux-headers-3.8.0-29-generic/include/linux/stat.h:18,
from /usr/src/linux-headers-3.8.0-29-generic/include/linux/module.h:10,
from cli.c:2:
/usr/src/linux-headers-3.8.0-29-generic/include/linux/linkage.h:5:25: fatal error: asm/linkage.h: No such file or directory
compilation terminated.
make: *** [cli.o] Error 1
wonder@wonder-VirtualBox:~/layer$

Makefile:

INCLUDEDIR = /usr/src/linux-headers-3.8.0-29-generic/include

CFLAGS = -D__KERNEL__ -DMODULE -O -Wall -I$(INCLUDEDIR)


OBJS = cli.o


all: $(OBJS)

install:
install -d /lib/modules/$(VER)/misc /lib/modules/misc
install -c cli.o /lib/modules/$(VER)/misc
install -c cli.o /lib/modules/misc

clean:
rm -f *.o *~ core

Last edited by zerop; 07-22-2014 at 05:47 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
VMware Server 2.0 on Ubuntu 9.10 - vmmon module, C header file, running kernel bmd5599 Linux - Newbie 7 03-31-2010 01:28 PM
LINUX UBUNTU PHP FFMPEG INSTALLED BUT libx264 while installing ERROR??? trinay123 Ubuntu 2 03-13-2010 10:22 AM
cant find header-linux/module.h sabarishr Programming 2 01-17-2008 12:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 06:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration