I have several files: so called library and kernel module, which uses functions from this library. All files are in the same directory.
lib.c:
#include <linux/module.h>
#include "lib.h"
volatile int check = 0;
int lib_in(void)
{
check = 5;
printk(KERN_ERR "In -> check:%d\n", check);
return 0;
}
void lib_out(void) { printk(KERN_ERR "Out\n"); }
MODULE_LICENSE("GPL");
lib.h:
int lib_in(void);
void lib_out(void);
some_mod.c:
#include <linux/init.h>
#include <linux/module.h>
#include <asm/string.h>
#include "lib.h"
static int __init mod_init(void)
{
printk(KERN_ERR "Loaded\n");
return lib_in();
}
static void ______wtf; mod_exit(void) // syntax error
{
printk(KERN_ERR "Unloaded\n");
lib_out();
}
Plain text - here also should be syntax error
MODULE_LICENSE("GPL");
module_init(mod_init);
module_exit(mod_exit);
While build it somehow doesn't compile some_mod object file (and even check its code), but it emits some_mod.ko
. By the way it compiles lib.c
. So the module could be correctly inserted but there is no output from printk
.
P.S. the errors in some_mod.c were added to underline that this code is not even compiled. That is the problem.
Makefile:
KDIR = /lib/modules/$(shell uname -r)/build
PWD = $(shell pwd)
TARGET = some_mod
LIB = lib
obj-m := $(TARGET).o
#$(TARGET)-y := $(LIB).o
$(TARGET)-objs := $(LIB).o
all: default
default:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
Can someone tell me what am I doing wrong? Thanks in advance.