LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 07: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, 04:32 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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 04:36 PM.
 
Old 03-03-2014, 07: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:37 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