LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-01-2014, 08:20 AM   #1
learningLinux123
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Rep: Reputation: Disabled
Makefile not working for kernel module


I have tried creating a make file to run a simple hello world module though keep getting the following error when I input make in the command line:

Code:
make -C /lib/modules/3.5.0-23-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-23-generic'
make[2]: *** No rule to make target `/usr/src/linux-headers-3.5.0-23-generic/arch/x86/syscalls/syscall_32.tbl', needed by `arch/x86/syscalls/../include/generated/asm/unistd_32.h'.  Stop.
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-23-generic'
make: *** [all] Error 2
I have tried two methods for creating the Makefile though keep getting the same above error:

1:
Code:
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
2:
Code:
obj-m += hello-1.o
KDIR = /usr/src/linux-headers-3.5.0-23-generic
all:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
        rm -rf *.o *.ko *.mod.* *.symvers *.order
Where could I be going wrong I have following some tutorials on creating kernel modules and have followed the tutorials word for word.
 
Old 03-02-2014, 05:32 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156
This is the basic "module Makefile" :
Code:
obj-m    := hello-1.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

clean:
	rm -f *.o *.ko *.mod.* *.symvers *.order

Last edited by knudfl; 03-02-2014 at 05:36 PM.
 
Old 03-03-2014, 08:53 AM   #3
rahil khera
LQ Newbie
 
Registered: Sep 2009
Posts: 14

Rep: Reputation: 0
In Make file just write :-
Code:
obj-m:= hello-1.o
without any space and run following command
Code:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
. But Instead of
Code:
 $(PWD)
write the whole path of makefile. Make sure the letter'M' in name of makefile is in Upper Case and also replace
Code:
$(shell uname -r)
with whole path of build, that I suppose in your case would be "3.5.0-23-generic". Make sure your c file and Makefile are in same directory i.e. folder.
 
  


Reply

Tags
makefile-module


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
kernel module makefile problem shiv garg Linux - Newbie 7 10-18-2013 11:34 AM
old 2.4 kernel module makefile reuse kannankvs Programming 0 08-18-2009 08:54 PM
how to edit makefile for kernel module? bhuvanmital Programming 5 02-02-2006 06:06 AM
need help in writing Makefile for module in 2.6 kernel videsh Linux - Software 3 01-19-2006 08:30 AM
module makefile for c++ in kernel 2.6 yuhuahe Linux - Software 0 04-14-2004 07:03 PM


All times are GMT -5. The time now is 01:31 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration