Member Avatar

Hey, so I'm having some difficulty getting my make file to work. When I try to make, I get this:

andrew@Samantha ~/Documents/OS_Projects/Chapter 6 $ ls
Makefile  Makefile_old  semaphore.c
andrew@Samantha ~/Documents/OS_Projects/Chapter 6 $ make
make -C /lib/modules/2.6.38-8-generic/build SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter 6 modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
make[1]: *** No rule to make target `6'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
make: *** [default] Error 2

My Makefile code is:

obj-m := semaphore.o
KDIR := /lib/modules/2.6.38-8-generic/build
PWD := $(shell pwd)
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

And what I'm trying to compile is:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/semaphore.h>
int num[2][5]={{0,2,4,6,8},{1,3,5,7,9}};

struct semaphore sem_first;
struct semaphore sem_second;
int thread_print_first(void *);
int thread_print_second(void *);

int thread_print_first(void *){
	int i;
	int *num=(int *)p;
		printk(KERN_INFO"Hello World: %d\n", num[i]);
	return 0;

int thread_print_second (void *){
	int i;
	int *num=(int*)p;
		printk(KERN_INFO"Hello World: %d\n", num[i]);
	return 0;

static int hello_init(void){
	printk(KERN_ALERT"Hello World enter\n");
	kernel_thread(thread_print_first,num[0], CLONE_KERNEL);
	return 0;

static void hello_exit(void) {
	printk(KERN_ALERT"hello world exit\n");

MODULE_AUTHOR("Andrew Stoker");
MODULE_DESCRIPTION("A simple hello world Module");
MODULE_ALIAS("a simplest module");

I'm really quite new to the whole "make" business, and I'm trying to make a module so I can practice adding a module to the kernel. Any ideas on why I'm getting this? I'm running the newest version of Linux Mint, but I also tried the newest version of Ubuntu. So my guess is that I have a critical mistake in my make file, or a really stupid one in my code. But I've looked over both...

Recommended Answers

All 3 Replies

The SUBDIRS variable contains a space. From make point of view, the line

make -C /lib/modules/2.6.38-8-generic/build SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter 6 modules

means that SUBDIRS=/home/andrew/Documents/OS_Projects/Chapter , while 6 and modules are targets to make. You may either rename your directory to Chapter_6, or change your makefile to something like

$(MAKE) -C $(KDIR) SUBDIRS=\"$(PWD)\" modules


For Linux Kernel Modules I just use

obj-m += test.o

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

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

Thanks! That did it! It was a stupid mistake with the space problem. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.