2.6 module compilation with make

Submitted by Anonymous
on January 28, 2009 - 12:43pm

Hi,
I have one kernel module ( one file ) mod.c

I want to divide this in some files.

lib1.h
lib1.c

lib2.h
lib2.c

mod.c

Please help me to write Makefile.

I have now this

CFLAGS= -Wall
obj-m := mod.o

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

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

but I dont understand what exactly "obj-m := mod.o" do in this file

I tried to write obj-m := mod.o lib2.o lib1.o
but when I tried use some function from lib2/lib1
in mod.c there are
WARNING: "testfunction" [/root/mod.ko] undefined!

I tried both #include "lib1.h" or extern int testfunction(int);

Ok I solve my problem with

zet (not verified)
on
January 28, 2009 - 2:16pm

Ok I solve my problem with

mod-objs := lib1.o lib2.o

thx

mmmmm I thought that I solve

zet (not verified)
on
January 28, 2009 - 4:27pm

mmmmm I thought that I solve my problem but not

obj-m := mod.o
mod-objs := lib1.o

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

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

IT's work this mean There is no compilation error and warnings

zet modulANDlibs # make
make -C /lib/modules/2.6.18-gentoo-r2/build SUBDIRS=/root/modulANDlibs modules
make[1]: Entering directory `/usr/src/linux-2.6.18-gentoo-r2'
CC [M] /root/modulANDlibs/lib1.o
LD [M] /root/modulANDlibs/mod.o
Building modules, stage 2.
MODPOST
CC /root/modulANDlibs/mod.mod.o
LD [M] /root/modulANDlibs/mod.ko
make[1]: Leaving directory `/usr/src/linux-2.6.18-gentoo-r2'
zet modulANDlibs #

but this is very strange dosn't matter what is in the mod.c file
the output mod.ko have 1.6K and it can be load by
insmod mod.ko
but nothing works ( printk etc. )

When I compile the same modul without any lib*
it works fine ( printk etc )

One adsitional

on
January 28, 2009 - 11:59pm

One adsitional information.

After module is loaded to kernel In /proc/kallsyms
there are symbols form [mod] for example testfunction
but still module doesnt work

Please help me guys. I realy need help I am desperated :)

Ever tried adapting one of

Anonymous (not verified)
on
January 29, 2009 - 5:31am

Ever tried adapting one of Jonathan Corbet's examples ? Look for examples from O'Reilly's LDD v3. I can provide it to you if you can't find it (the examples are mostly dual GPL/BSD licenses)

Thx I read one sentence from

on
January 30, 2009 - 11:56am

Thx I read one sentence from Chapter 02 of LDD v3 and this help my mind to understand :)

The right solution is

obj-m := new_virtual_name_of_module.o
new_virtual_name_of_module-objs := mod.o lib1.o lib2.o

Thx again :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.