Linking Custom Library to Linux Kernel Module in the Makefile

Jereme Lamps

So I am trying to re-factor a kernel module I have previously written (by removing certain functions into different a different .h/.c file. Here is my current Makefile:


EXTRA_CFLAGS += 
KERNEL_SRC:= /lib/modules/$(shell uname -r)/build
SUBDIR= $(PWD)
GCC:=gcc
RM:=rm

.PHONY : clean

all: clean modules

obj-m:= kernel_module.o

modules:
    $(MAKE) -C $(KERNEL_SRC) M=$(SUBDIR) modules

clean:
$(RM) -f *.ko *.o *.mod.c Module.symvers 

When I try to make it, I get: error: ‘ref_sleep’ undeclared (first use in this function). How do I modify the Makefile to make sure my library is getting compiled, and it is being linked properly to my kernel module? It is worth nothing that the library needs variables defined in the kernel module, and vice versa.

Thanks in advance.

Eugene

If I understand the problem correctly, you would like to build your kernel module (say, my_module.ko) from several source files (e.g., source1.c, source2.c, source3.c). If so, you can do it as follows in the Makefile:

obj-m := my_module.o
my_module-y := source1.o source2.o source3.o

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Linking shared library in linux kernel

From Dev

Makefile for linux kernel module issue

From Dev

Compiling a kernel module using makefile in linux

From Dev

Compiling Linux Kernel Module With A Custom Header

From Dev

Makefile for a basic kernel module

From Dev

Makefile Linking with shared library fails

From Dev

Linking kernel module with precompiled object

From Dev

SUBDIRS variable in kernel module makefile

From Dev

Kernel module makefile output name

From Dev

Custom Linux kernel module to display year, date and time

From Dev

Error compiling Linux kernel module using custom system calls

From Dev

Custom Linux kernel module to display year, date and time

From Dev

C: Creating static library and linking using a Makefile

From Dev

Basic makefile/linking/library issue: No such file or directory

From Dev

c++ MakeFile linking to SQlite library

From Dev

linking custom framework to library in xcode

From Dev

How to load custom Linux kernel module that is not Linux kernel version dependant using RPM

From Dev

Library routines in linux kernel

From Dev

Linux kernel makefile cscope target

From Dev

build variable in Linux kernel Makefile

From Dev

Disadvantages of linux kernel module?

From Dev

linux kernel module not autoloading

From Dev

Linux kernel module programming

From Dev

Disadvantages of linux kernel module?

From Dev

Linux Kernel Module Compilation

From Dev

Custom Kernel module not being loaded

From Dev

Ubuntu 15.10 (Kernel 4.2): Hello world kernel module makefile error

From Dev

Linux Kernel Module development compile for other kernel

From Dev

undefined references when linking with static library with OTL using a makefile

Related Related

HotTag

Archive